In this tutorial, you will learn about the new way to hook into the Umbraco events handling pipeline. It is very common that some functionality will require you to perform some additional actions, like adding some validation to a page before it is allowed to be saved.

In Umbraco V8 the concept of components was introduced. Components are the new way of hooking into Umbraco. Although components can be used for numerous purposes, the focus of this article is event handling, so we focus on how to create and register components specifically for event handling. Components are the new way to hook into the Umbraco pipeline and register your own custom functionality. There are two parts to creating a custom component:

  • Creating The Component
  • Registering The Component With Umbraco

Registering The Component With Umbraco

Registering a component is easy. Create a new class that inherits from ComponentComposer where T is the type-definition of as your custom component class, like so:

This class can live anywhere in your solution. When Umbraco loads it will use reflection to find all instances of ComponentComposer and register it for you. The next step is to create a component. The component is the place where you will add all of your custom code. The code to create a component is shown below:

As Umbraco 8 uses dependency injection, if you want access to an API you will need to inject it via the constructor, like so:

With these two simple classes, you have access to do a lot of powerful things within Umbraco. Asides from hooking into the save event, there are a number of custom events that you can hook into, these include:

A full list of the events for content can be found here and for media requests here. Enjoy!