Events are notifications that are broadcasted to interested parties. Events can be triggered on data changes like inserts, updates and deletes. There should be a publisher and consumer (subscriber) for events.
Subscribe for event
It needs to create a new implementation of the generic event handler interface IObserver
//This line registers new event publisher for OrderChangeEvent _container.RegisterType<IEventPublisher<OrderChangeEvent>, EventPublisher<OrderChangeEvent>>(); //This line register event handler. "AdjustInventoryObserver" name in IoC type registration it necessary for correct publisher type resolving. _container.RegisterType<IObserver<OrderChangeEvent>, AdjustInventoryObserver>("AdjustInventoryObserver");
First it needs to inject IEventPublisher
_eventPublisher.Publish(new OrderChangeEvent(EntryState.Added, null, order));
Events processing priority
In situations when it needs to prioritize event processing, you can define an event handler with priority for your event handler execution. It needs to implement the event handler from IPriorityObserver interface and set the Priority property, which should return integer priority value. Smaller value means higher priority. That means the event handler with priority 10 will be called earlier than the handler with priority 20.
Customer order and shopping cart events
VCF has event types OrderChangeEvent and CartChangeEvent which are raised when the shopping cart or customer order is changed, created or deleted. Each event has information about changing type and also contains original and modified objects instances for finding out changes made in order or cart.
You can define custom OrderChangeEvent or CartChangeEvent handlers in your module and thereby infiltrate into the customer order and shopping cart processing.