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.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. 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?