Search code examples
c#castle-windsorinterceptorcastlefacilities

Registeting interceptors after Component registration in Castle


I have a facility which needs to register an interceptor and then register this interceptor against a subset of the components already registerd in the container Castle Kernel.

The facility lives in a separatee assembly and it is meant to be used from different assemblies so I cannot couple the interceptor registration with the component registration of each assembly that uses this facility.

Is it possible to do this? How can I achieve this functionality?


Solution

  • Normally the way I use facilities is like this:

    // 1. create the container
    var container = new WindsorContainer();
    
    // 2. add all the facilities I need
    container.AddFacility<SomeFacility>();
    contianer.AddFacility<SomeOtherFacility>();
    
    // 3. install all the components
    container.Install(FromAssembly.This());
    

    The facilities usually either subscribe to container events, register some of their own components, or add ComponentModel construction contributors that examine and augment ComponentModel of components being registered.

    That way it can be completely transparent to components and imposes to explicit coupling between components and facility (unless you want it).