Implement custom EventHub events

Although Sitefinity CMS provides many events raised by the built-in modules, you can also create your custom events providing hooks to your code. In order to implement a custom event, you need to follow 3 steps.

Create the interface and its implementation

All events provide an interface specifying the contract for the event. The interface has all properties that will be passed to the event handler as data. You should implement a custom interface for your event and include any properties you want. All interfaces should implement the IEvent interface.

When you raise the event, you will need to create an instance which will be passed to the handler. Since you cannot create interface instances, you will need a class which implements the interface.

Raising the event

Whenever you want to invoke the event handlers which have subscribed to your event, you should raise it. This can be done using a helper method of the EventHub class.

After you've done this, everyone will be able to subscribe to your event using the ICustomEvent interface. For more information on subscribing, read For developers: Work with events.

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Web Security for Sitefinity Administrators

The free standalone Web Security lesson teaches administrators how to protect your websites and Sitefinity instance from external threats. Learn to configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?