Nucleus .Net Core CMS

EventHandlers.IEventDispatcher Interface

Namespace: Nucleus.Abstractions.EventHandlers
Assembly: Nucleus.Abstractions.dll
Raises notification events. Internal and custom implementations can acquire a reference to EventDispatcher from the dependency injection services container and raise or consume events.

Remarks

To handle an event, create an implementation of EventHandlers.ISystemEventHandler<TModel, TEvent> and add it to the dependency injection services container in your Startup Class. Event handlers can be added as Scoped, Singleton or Transient. If your event is expected to be triggered during a Http request, you can add your handler with .AddScoped - scoped handlers can use references to other scoped classes (like Models.Context) to get information about the current request. <br /><br /> If your event is not expected to run during a Http request (from a scheduled task, or during startup), use .AddSingleton or .AddTransient to add your event handler to the dependency injection services container.<br /><br /> Any number of event handlers may exist for any number of combinations of TModel and TEvent. ISystemEventHandlers are invoked asynchronously in no particular order.<br /><br /> To raise an event, get a reference to the event dispatcher by including a parameter of type EventHandlers.IEventDispatcher in your class constructor, and call RaiseEvent<TModel, TEvent>. <br /><br /> TModel can be any class type. TEvent can also be any class type, but is normally a class created specifically to mark an event type, with no methods or properties. Developers can use the EventHandlers.SystemEventTypes.Create, EventHandlers.SystemEventTypes.Delete or EventHandlers.SystemEventTypes.Update events, or create specific classes for custom events.

Examples

// Adding an event handler: 
services.AddTransient<ISystemEventHandler<User, Create>, UserEventHandler>();
// Raising an Event: 
eventDispatcher.RaiseEvent<User, Create>(myuser)

Methods

RaiseEvent<TModel, TEvent> (<TModel>) Method

RaiseEvent<TModel, TEvent> (<TModel> item)
Call RaiseEvent to submit an event to the Event Dispatcher. The Invoke method will be called for all implementations of ISystemEventHandler{TModel, TEvent} in the services collection.
Type Parameters
TModel
TEvent
Parameters
Name Type
item <TModel>