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...).
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.
container.AddFacility<TypedFactoryFacility>();
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 (deprecated) - 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 ofUsingFactoryMethod
. Factory Support Facility may become obsolete in future release.
- ℹ️ Prefer
- Event Wiring Facility (deprecated) - Provides ability to wire up classes exposing events to classes consuming them.
- Remoting Facility (deprecated) - Provides ability to expose or consume components from another
AppDomain
using .NET Remoting. - ActiveRecord Integration Facility (deprecated) - The ActiveRecord Integration Facility takes care of configuring and starting Castle ActiveRecord and adds declarative transaction support integration.
- NHibernate Integration Facility (deprecated) - When you're using bare NHibernate, rather than Castle ActiveRecord, this facility offers nice integration between the two frameworks.
- Synchronize Facility (deprecated) - Integrates with synchronization elements of .NET Framework (like
ISynchronizeInvoke
interface,SynchronizationContext
), ensures components that inheritControl
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 (deprecated) - 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.
ℹ️ 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.
- 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
- NServiceBus
- MassTransit
- re-motion
- Rhino Service Bus
- Rhino Security
- Quartz.Net - Provides integration with Quartz.Net jobs and listeners.
- SolrNet
- SolrSharp
- Windows Fax Services
- App Config Facility