Welcome Guest, you are in: Login

Castle Project

RSS RSS

Navigation (Windsor)






Search the wiki
»

PoweredBy

This documentation is a work in progress.

Let us know if some information is not clear, inaccurate or missing. Also feel free to update the wiki yourself.

Facilities

RSS
Modified on 2013/01/30 23:58 by SamAtFPS Categorized as API, Extensions, Facilities, TODO

Introduction

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.

container.AddFacility<TypedFactoryFacility>();

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

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

Image
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.
    Image
    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.




  • Remoting Facility - Provides ability to expose or consume components from another AppDomain using .NET Remoting.



  • Synchronize Facility - Integrates with synchronization elements of .NET framework (like ISynchronizeInvoke interface, SynchronizationContext), ensures components that inherit Control get created on UI thread etc.
    //TODO: add better description

  • 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.


  • //TODO: add other facilities we offer

Third party facilities

Image
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.

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



  • 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.











See also

ScrewTurn Wiki version 3.0.4.560. Some of the icons created by FamFamFam.