Eventing library using Mediatr.
Add the library to a project, add the following in the project.json :
"Quixilver.Mediatr": "1.1.0"
Register the eventing services and event handlers in the ConfigureServices method of the Startup class :
service.AddEventing(options => {
options.RegisterEventHandler<AnEvent, MyEventHandler>();
options.RegisterAsyncEventHandler<AnotherEvent, MyAsyncEventHandler> ();
});
You can publish synchronous and asynchronous events with the IEventPublisher. All events must inherit from the AppEvent class.
Publishes an event to all event handlers that are attached for the given type of event. The method returns when all event handlers have finished handling the event.
var myEvent = new MyEvent() { /* initialize some properties*/ } ;
eventPublisher.Publish(myEvent);
// code below the above statement will execute when all subcribed event handler have handled the event
With the PublishAsync method, the event handlers are called asynchronously and the method returns immediately.
var myEvent = new MyEvent() { /* initialize some properties*/ } ;
eventPublisher.PublishAsync(myEvent);
// code below the above statement will immediately execute
If you want to wait until all event handlers have handled the event, you can use the await statement.
var myEvent = new MyEvent() { /* initialize some properties*/ } ;
await eventPublisher.PublishAsync(myEvent);