construction contributors are objects that implement
interface. As their name implies they construct the
into its final state right after it was created.
ComponentModel outside of contributors
It is discouraged to modify component model elsewhere than in construction contributors. After
is processed by its construction contributors it should be considered read only. Modifying it at any later point may lead to concurrency issues and other kinds of hard to track down issues.
ComponentModel construction contributors are required to implement single method:
void ProcessModel(IKernel kernel, ComponentModel model);
Based on the information provided by other contributors, kernel, model's configuration or its own state they either inspect or modify the
parameter. Windsor uses several of built in contributors itself to set up things like proxying, parameters, lifestyles, lifecycle steps, dependencies etc.
Writing your own
Writing custom contributor is one of the most common ways of extending/customizing Windsor. For the sake of example let's say we want to make all properties of type
on all components to be mandatory (By default property dependencies are optional in Windsor). To do that we could write a contributor that looks like the following:
public class RequireLoggerProperties : IContributeComponentModelConstruction
public void ProcessModel(IKernel kernel, ComponentModel model)
.Where(p => p.Dependency.TargetType == typeof(ILogger))
.All(p => p.Dependency.IsOptional = false);
The contributor scans all property dependencies of each component, trying to find ones that have type
and marks them as mandatory.
Plugging the contributor in
When you create your contributor you need to add it to the collection of contributors on container's
container.Kernel.ComponentModelBuilder.AddContributor(new RequireLoggerProperties ());
Blogpost by Mark Seemann (Apr 26, 2010)Blogpost by Ayende (Mar 11, 2007)