In this tutorial, you will learn all about the concepts of composers and components. In Umbraco 7 - and a lot of other vanilla MVC ASP.NET websites you would hook into the pipeline within the global.acsx to run custom configurations. Within V* this is no longer the case, instead you use
components. The official Umbraco documentation describes composing as:
An Umbraco application is a composition made of many different 'collections'. 'Composing' is the term used to describe the process of curating which pieces of functionality should be included in a particular collection. The code that implements these choices at startup is called a Composer.
That is very jargon-heavy so let us break it down into simpler terms. A component is used to add functionality on start-up. A composer is used to compose that functionality into the pipeline. This is why components and composers kind of go hand in hand. Whenever you need to build some new functionality on Umbraco start-up you will be creating a component. Each component will need to register by a composer.
Umbraco ships with three types of composers:
IUserComposer is the type that you as an application developer will be working with. User composer => components designed to be used by developers to add-in functionality, get it?
When creating a composer, the order in which they load might be important too. You can set the order by declaring either the
[ComposeAfter] attributes on the class. One word of caution when using these attribute is a circular dependency, If you accidentally create a circular dependency, e.g. composer one calls composer two and composer two call composer one. Umbraco will blow up and call a StackOverflow error.
V8 also ships with the
[Disable] attributes. As the name implies these attributes allow you either enabled or disable a component. On their own these properties are probably less useful for normal developers. If you are a package developer, or, you want to override how some core functionality works, then one feature of these attributes that may be handy is the ability to disable a different composer. This can be done like this:
When creating a custom component there are two methods that you will need to implement,
Initialize() will be called on start-up. This is the one you will be using the most.
Terminate() is called on application stop. In general, you can usually implement an empty terminate method and not worry about it. Below shows an example of a component:
Umbraco obviously ships with a number of core components that allow the CMS to function. I won't cover these here. If you ware really interested, you can download the Umbraco source-code and search for
IComponent to find them