【发布时间】:2011-07-17 12:20:39
【问题描述】:
我正在尝试创建一个工具,该工具将根据类属性将一些拦截器添加到已注册的类中。 这是我的设施:
public class MyFacility : AbstractFacility
{
protected override void Init()
{
this.Kernel.ComponentRegistered += (s, h) =>
{
if (h.ComponentModel.Implementation.GetCustomAttributes(typeof(MyAttribute), false).Length > 0)
{
h.ComponentModel.Interceptors.Add(InterceptorReference.ForType<MyInterceptor>());
}
}
}
}
但是这样,当我在类方法中使用 this 关键字时,它指的是目标类而不是代理类,这使得我使用的某些框架无法正常工作。
我需要使用ProxyGenerator.CreateClassProxy<MyClass>() 方法生成的相同代理创建一个工具。
我怎样才能做到这一点?
【问题讨论】:
-
你能显示更多代码吗?你注册的组件是接口还是类?
-
我注册的组件是一个接口。这是 Windsor 安装: _wc = new WindsorContainer(); _wc.AddFacility
(); _wc.Register( Component.For () ); _wc.Register(Component.For ().ImplementedBy ());
标签: c# castle-windsor facilities