代码之家  ›  专栏  ›  技术社区  ›  Quintin Par

用Castle Fluent接口注册拦截器

  •  2
  • Quintin Par  · 技术社区  · 16 年前

    我正在努力实现 nhibernate transaction handling 通过拦截器,无法通过fluent机制计算出如何注册接口。

    我看到了

    Component.For<ServicesInterceptor>().Interceptors
    

    但不知道如何使用它。有人能帮我吗? This example 好像有点复杂。

    2 回复  |  直到 14 年前
        1
  •  6
  •   Maciej    14 年前

    您可以分两步完成:

    • 您需要将拦截器注册为容器中的服务:
    container.Register(Component.For<MyInterceptor>());
    
    • 注册要拦截的组件。使用 Interceptors 方法在Fluent API上指定要用以下方法截取此组件的注册截取器(按键或类型):
    container.Register(Component.For<IFoo>().ImplementedBy<Foo>()
       .Interceptors<MyInterceptor>());
    

    见 the documentation 了解更多详细信息。

        2
  •  1
  •   Otávio Décio    16 年前

    首先注册拦截器:

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

    然后注册被截取的对象:

    container.register(component.for<imyservice>().implemented by<myservice>().named(“myservice”)。拦截器(新 interceptorreference(“transactionInterceptor”)).anywhere);