Skip to content

Define Events

Shreyas Jejurkar edited this page Aug 23, 2020 · 3 revisions

Defining an event is quite simple with Eventify.

The corresponding class needs to implement the abstract base Event class which is available from the Eventify package. By doing so, the eventify package now considers given class as an Event in the system.

The base class Event adds a Guid field for eventId parameter and DateTime parameter which stores the DateTime when the given event has occurred in the system. Following is a simple example of creating a CustomerRegisteredEvent.

public class CustomerRegisteredEvent : Eventify.Event
{
   private Customer _newCustomer;

   public Customer RegisteredCustomer = get => _newCustomer;

   public CustomerRegisteredEvent(Customer newlyRegisteredCustomer)
   {
      _newCustomer = newlyRegisteredCustomer;
   }
}

Event can also take parameters for their task. In the above example, the CustomerRegisteredEvent constructor takes Customer object as a parameter, so that event can know which customer has been registered, then we are storing it in private variable _newCustomer for further processing.

Now we have event in place, let's see how to declare the EventHandler for this event.

Defining Event Handlers.

Clone this wiki locally