给出以下代码:
container.Register(
AllTypes.FromAssemblyNamed("MyNameSpace")
.Where(component => component.Name.EndsWith("Repository"))
.WithService.FirstInterface()
.Configure(component => component.LifeStyle.Singleton)
);
是否可以为找到的所有组件引入拦截器(例如LoggingInterceptor)?我现在唯一的办法是打破每个组件并明确添加拦截器,我发现这是直观的,因为它们将使用一个拦截器(即LoggingInterceptor)。
由于
答案 0 :(得分:1)
container.Register(
AllTypes.FromAssemblyNamed("MyNameSpace")
.Where(component => component.Name.EndsWith("Repository"))
.WithService.FirstInterface()
.Configure(component => component.LifeStyle.Singleton.Interceptors(InterceptorReference.ForType<LoggingInterceptor>()))
);
container.Register(Component.For<LoggingInterceptor>());