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());
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.
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
HttpContextin the container.
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
AppDomainusing .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
SynchronizationContext), ensures components that inherit
Controlget 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
- 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
Here's a partial list of facilities for Windsor offered by different other projects.
- ASP.NET MVC
- WCF Session Facility - Part of Sharp Architecture project, this facility may be registered within your web application to automatically look for and close WCF connections. This eliminates all the redundant code for closing the connection and aborting if any appropriate exceptions are encountered.
- Workflow Foundation
- Rhino Service Bus
- Rhino Security
- Quartz.Net - Provides integration with Quartz.Net jobs and listeners.
- Windows Fax Services
- App Config Facility