73 lines (52 sloc) 7.68 KB


Facilities are the main way of extending the container. Using facilities you can integrate the container with external frameworks, like WCF or NHibernate, add new capabilities to the container like event wiring, transaction support... or to components (synchronization, startable semantics...).

How to use them

To start using a facility you need to register it with the container, either in code, as shown below or using XML configuration. Usually that's all you need to do as a user. Some facilities, most notably WCF facility may have also additional API, detached from the container object but that's something specific to a given facility.


Some facilities can also be configured, using an overload of the above method:

container.AddFacility<StartableFacility>(f => f.DeferredTryStart());

⚠️ Add facilities at the beginning: In order to work properly most facilities need to be registered before components they affect. Keep that in mind when structuring your registration code, as forgetting to do so may lead to some hard to find issues (like startable components not being started).

Standard facilities

In container's assembly Castle.Windsor.dll you can find the following facilities. Notice that the are many more provided in their own assemblies, but still being part of the Castle project. Many external projects provide their own facilities to integrate with Windsor.

  • Typed Factory Facility - Provides automatic implementation for factory classes, that you can use in your code to create objects on demand without introducing dependency on the container.
  • Startable Facility - Provides ability to 'start' and 'stop' objects. Very useful for things like WCF Services that you may want started as soon as your application starts.

Other facilities

In addition to the above, as part of Castle Project, some other facilities are provided, mostly for integration between Windsor and other frameworks. They also contain some pretty powerful features and can ease your job significantly.

  • WCF Integration Facility - Provides integration with Windows Communication Foundation. It dramatically simplifies configuring of your WCF services lets you extend them easily, use non-default constructors, call services asynchronously without having to resort to code generation and more.
  • Logging Facility - Most applications use logging. This facility lets you easily inject loggers into your components. It offers integration with most popular 3rd party logging frameworks like NLog and log4net.
  • Factory Support Facility - Provides ability for the components to be created by factory objects. You can use it to register things like HttpContext in the container.
    • ℹ️ Prefer UsingFactoryMethod: This facility is used mostly for backward compatibility (XML registration) and it is discouraged to use it in new applications. Prefer usage of UsingFactoryMethod. Factory Support Facility may become obsolete in future release.
  • Event Wiring Facility - Provides ability to wire up classes exposing events to classes consuming them.
  • Remoting Facility - Provides ability to expose or consume components from another AppDomain using .NET Remoting.
  • ActiveRecord Integration Facility - The ActiveRecord Integration Facility takes care of configuring and starting Castle ActiveRecord and adds declarative transaction support integration.
  • NHibernate Integration Facility - When you're using bare NHibernate, rather than Castle ActiveRecord, this facility offers nice integration between the two frameworks.
  • Synchronize Facility - Integrates with synchronization elements of .NET Framework (like ISynchronizeInvoke interface, SynchronizationContext), ensures components that inherit Control get created on UI thread etc.
  • Automatic Transaction Management Facility - This facility manages the creation of Transactions and the associated commit or rollback, depending on whether the method throws an exception or not. Transactions are logical. It is up the other integration to be transaction aware and enlist its resources on it.
  • MonoRail Integration Facility - Provides integration with MonoRail controllers and internal services.
  • System Web Facility - Provides System.Web integration for web projects using PerWebRequest lifestyles.
  • ASP.NET MVC Facility - Provides ASP.NET MVC integration for web projects using Windsor.
  • ASP.NET WebApi Facility - Provides ASP.NET Web API integration for web projects using Windsor.
  • ASP.NET Core Facility - Provides ASP.NET Core integration for web projects using Windsor.

Third Party Facilities

ℹ️ More facilities: Facilities are primary way of extending and integrating with Windsor container. Multiple other projects, like MVC Contrib, OpenRasta, NServiceBus to name just a few offer their own ready to use facilities that help you use these frameworks with Windsor.

Here's a partial list of facilities for Windsor offered by different other projects.

ℹ️ If you know of any other projects offering facilities, go ahead and add them to the list.

See also