versionFrom | meta.Title | meta.Description |
---|---|---|
8.0.0 |
Handling application startup events in Umbraco |
How to handle application startup events in Umbraco |
The ApplicationEventHandler
approach for registering events has been removed in Umbraco 8. The new approach for registering custom code at the ApplicationStarting
and ApplicationStarted
events uses a combination of 'Composers' and 'Components', you can find a basic example below and more detailed ones on the Composing page.
Core developer Stephan also has a series of blog posts about the changes:
The following code uses a ComponentComposer<T>
to add the ApplicationComponent
. You can optionally override the Compose()
method if you want to compose more than only adding the component (make sure to keep the call to the base method, as the component isn't added otherwise).
public class ApplicationComposer : ComponentComposer<ApplicationComponent>, IUserComposer
{
public override void Compose(Composition composition)
{
// ApplicationStarting event in V7: add IContentFinders, register custom services and more here
base.Compose(composition);
}
}
public class ApplicationComponent : IComponent
{
public void Initialize()
{
// ApplicationStarted event in V7: add your events here
}
public void Terminate()
{ }
}