使用Castle Fluent界面注册拦截器
我试图通过拦截器实现nhibernate事务处理 ,并无法弄清楚如何通过流畅的机制注册接口。
我看到了
Component.For().Interceptors
但不知道如何使用它。 有人可以帮我吗? 这个例子似乎有点复杂。
你分两步完成:
- 您需要将拦截器注册为容器中的服务:
container.Register(Component.For
());
- 您注册要拦截的组件。 在Fluent API上使用
Interceptors
方法,您可以指定要拦截此组件的已注册拦截器(按键或类型):
container.Register(Component.For
().ImplementedBy () .Interceptors ());
有关详细信息,请参阅文档 。
首先注册拦截器:
container.Register(Component.For
().ImplementedBy ().Named("transactionInterceptor"));
然后注册截获的对象:
container.Register(Component.For
()。ImplementedBy ()。Named(“MyService”)。Interceptor(new InterceptorReference(“transactionInterceptor”))。Anywhere);