Work with EventHub events

Each event, both its identity and the associated data, is represented by an interface that inherits the IEvent interface. For instance the IMediaContentDownloadedEvent represents the event that a media content item (e.g. image) has been downloaded by a user and also defines some properties that provide contextual information about the concrete event – which image, from which library, etc.

Subscribe for an event

To subscribe for a particular event, you call the Subscribe method of the event service and pass the event interface as a generic argument. You can either use the lambda expression syntax to directly pass the executable code, or provide a separate delegate that will be invoked.

Lambda expression

Delegate

Unsubscribe from an event

In order to unsubscribe, you need an instance of the delegate you passed when you subscribed. You pass it as an argument to the Unsubscribe method of the event service and again use the event interface as a generic argument.

"Before" and "after" events

Events exposed by Sitefinity CMS conform to the popular .NET naming convention. Events that are fired before an action are prefixed with “-ing”, while events that fire after an action are sufixed with “-ed”. For example, The “UserCreating” event will fire before a user is created, while the “UserCreated” event will fire after the user has been created.

Was this article helpful?