Skip to content

Latest commit

 

History

History
59 lines (37 loc) · 2.43 KB

fluent-registration-api.md

File metadata and controls

59 lines (37 loc) · 2.43 KB

Fluent Registration API

The Registration API provides a fluent method of registering and configuring components. It is the recommended way of doing so, over meticulous registration in XML. It can be used as an alternative or in addition to XML configuration, with the advantage that it is typed and will be easier to include in refactoring. It may also be advantageous to mix it with some XML.

Requirements

Castle.Core.dll and Castle.Windsor.dll are both required. You need to add a using directive to Castle.MicroKernel.Registration in order to use this API. The examples which follow assume you have created the Windsor Container thusly:

IWindsorContainer container = new WindsorContainer();

We will use the container instance throughout the API documentation.

Registering components one-by-one

Fluent API has ability to register components on a one-by-one basis, where you can explicitly configure all aspects of the component. (read more)

Registering components by convention

Recommended approach to registering components is to do it using convention driven approach, which can significantly reduce friction and amount of code required to configure the application. (read more)

Proxies

Registering interceptors and proxy options.

Advanced topics

If you're interested in advanced topics, like pieces of the API targeted at extending the components read advanced topics.

Using with XML Configuration

If you need to mix both styles of registration there are two options. If the Xml configuration can happen first, simply use the constructor overload that takes an Xml file name before using the fluent api for the rest.

IWindsorContainer container = new WindsorContainer("dependencies.config");

container.Register(
	Component.For....
);

If the fluent registrations must happen first, add the following after all of your fluent calls.

container.Register(
	Component.For....
);

container.Install(
    Configuration.FromXmlFile("dependencies.config"));

See also