container
.Register
(
AllTypes
.FromAssemblyContaining<TestInterceptor>()
.BasedOn<IInterceptor>()
.Where(t => t.Name.EndsWith("Interceptor"))
.WithService.AllInterfaces()
.Configu开发者_运维技巧re(c => c.LifeStyle.Transient),
Component
.For<IRepository>()
.ImplementedBy<LogRepository>()
.Interceptors
(
InterceptorReference.ForType<TestInterceptor>(),
InterceptorReference.ForType<TestTwoInterceptor>(),
InterceptorReference.ForType<TestThreeInterceptor>()
).Anywhere
);
Is there an easy way to specify that a component will use all interceptors instead of having to specify each one?
That's an interesting problem. There's no out of the box way to solve it in the fluent API, mostly because most of the time you do want to have a fine grained control over which interceptors to apply, and in what order. This is a surgical tool.
Anyway, if you're sure you need to go this way register the interceptors first, then grab their names (via container.Kernel.GetAssignableHandlers(typeof(IInterceptor))
) and in a loop apply all of them to the component.
精彩评论