1
votes

I'm using Castle Dynamic Proxy interceptor in my code (for logging purpose). I know how to set the interceptor on a dependency, like that:

      container.Register(Component.For<MyService>().
           Interceptors<LoggerInterceptor>());

But how can i set this interceptor to ALL my dependencies?

2

2 Answers

2
votes

Before you do any registration of your components you can add a handler that will add your interceptor to every component:

        container.Kernel.ComponentRegistered += (key, handler) =>
        {
            handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(LoggingInterceptor)));
        };
1
votes

Use convention registration:

container.Register(Classes.FromThisAssembly()
                          .Pick()
                          .WithService.Self()
                          .Configure(r => r.Interceptors<LoggerInterceptor>()));