Reputation: 173
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?
Upvotes: 1
Views: 419
Reputation: 7264
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)));
};
Upvotes: 2
Reputation: 4408
Use convention registration:
container.Register(Classes.FromThisAssembly()
.Pick()
.WithService.Self()
.Configure(r => r.Interceptors<LoggerInterceptor>()));
Upvotes: 1