문제

I am trying to implement nhibernate transaction handling through Interceptors and couldn’t figure out how to register the interface through fluent mechanism.

I see a

Component.For<ServicesInterceptor>().Interceptors

but not sure how to use it. Can someone help me out? This example seemed a little complex.

도움이 되었습니까?

해결책

You do it in two steps:

  • You need to register the interceptor as a service in the container:
container.Register(Component.For<MyInterceptor>());
  • You register the component you want to intercept. Using Interceptors method on fluent API you specify which of the registered interceptors (by key, or type) you want to intercept this component with:
container.Register(Component.For<IFoo>().ImplementedBy<Foo>()
   .Interceptors<MyInterceptor>());

See the documentation for more details.

다른 팁

First register the interceptor:

container.Register(Component.For<IDbInterceptor>().ImplementedBy<DbInterceptor>().Named("transactionInterceptor"));

Then register the objecting being intercepted:

container.Register(Component.For<IMyService>().ImplementedBy<MyService>().Named("MyService"). Interceptors(new InterceptorReference("transactionInterceptor")).Anywhere);

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top