Search code examples
castle-windsorcastle-dynamicproxy

How do you inject a Logging interceptor into a Windsor Controller Factory?


How do you add an Exception or Logging interceptor into a Windsor Controller Factory using fluent configuration?

In my bootstrapper container I new up my installers to pass in values like assemblyName.

In my ControllerInstaller I do this, which I think is wrong and why it is not working:

container.Register(
    Classes
        .FromAssemblyNamed(_assemblyName)
        .BasedOn<IController>()
        .LifestyleTransient(),
    Component
        .For<IController>()
        .ImplementedBy<Controller>()
        .Interceptors(InterceptorReference.ForType<LoggingAspect>())
        .Anywhere);

In my loggingAspect installer I do this:

container.Register(
    Component
        .For<IInterceptor>()
        .ImplementedBy<LoggingAspect>());

Solution

  • I think this should work...

    _container.Register(
        Classes
            .FromAssemblyNamed(_assemblyName)
            .BasedOn<IController>()
            .LifestyleTransient()
            .Configure(component => component.Interceptors<LoggingAspect>()));