使用Castle Fluent界面注册拦截器 [英] Register an Interceptor with Castle Fluent Interface

查看:66
本文介绍了使用Castle Fluent界面注册拦截器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试实施通过拦截器进行的休眠事务处理,无法弄清楚如何通过流畅的机制来注册接口。

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

我看到了

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:


  • 您需要将拦截器注册为容器中的服务:


container.Register(Component.For<MyInterceptor>());





  • 您注册所需的组件拦截。在fluent API上使用 Interceptors 方法,您可以指定要使用以下哪个拦截器(按键或类型)拦截该组件:

    • 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.

      这篇关于使用Castle Fluent界面注册拦截器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆