c# - CaSTLe DynamicProxy 接口(interface)代理生成

标签 c# .net castle-windsor aop castle-dynamicproxy

我有一个 WindsorContainer。

我有一个 ILazyComponentLoader (如果重要的话)和一个带有拦截器属性的接口(interface)(ISomething)。

[Interceptor(typeof(DynamicImplementationInterceptor)]
public interface ISomething

我想让温莎使用 ProxyGenerator.CreateInterfaceProxyWithoutTarget通过 container.Resolve<ISomething>() 解析接口(interface)时这样我的DynamicImplementationInterceptor可以在外部按需实现所有行为。

我似乎无法在文档中找到这个确切的场景...当我注册 ISomething 时通过使用 Component.For<ISomething>().... ,如何指定我想要这种行为? (目前我得到一个关于类型是抽象或接口(interface)的错误,所以它不能被实例化......)

谢谢!

最佳答案

当你用拦截器注册组件但没有实现时,Windsor 会自动省略目标,例如:

var container = new WindsorContainer();
container.Register(Component.For<DynamicImplementationInterceptor>());
container.Register(Component.For<ISomething>()
    .Interceptors(InterceptorReference.ForType<DynamicImplementationInterceptor>()).First);

不需要任何拦截器属性

关于c# - CaSTLe DynamicProxy 接口(interface)代理生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3896444/

相关文章:

c# - 选择其中一个功能

c# - 内线程异常处理

c# - 如何延长 SolrConnection 中的超时? (SolrConnection异常: The operation has timed out)

inversion-of-control - 通过参数名称解​​决 CasSTLe Windsor 依赖关系

c# - Unity Build错误::audioinaec中的属性application @ allowBackups = false:与另一个值冲突

c# - asp.net SERVER_NAME 返回错误的域名

c# - Windows 窗体中用于实时搜索的文本框

c# - 如何检测另一个音频是否在后台播放? ( window 电话 7)

c# - 计算不同年份不同日期的平均值

.net - 温莎城堡 : So what DOES ActAs do?