【发布时间】:2018-08-30 21:56:29
【问题描述】:
我确实使用了这个文档: https://autofaccn.readthedocs.io/en/latest/advanced/interceptors.html
实现接口拦截器。为了处理我的异步调用,我使用了此处描述的 IAsyncInterceptor 接口:
https://github.com/JSkimming/Castle.Core.AsyncInterceptor
我想出的注册码是这样的:
builder.Register(c => new CallResultLoggerInterceptor())
.Named<IAsyncInterceptor>("log-calls");
builder.RegisterType<AppointmentService>()
.As<IAppointmentService>()
.EnableInterfaceInterceptors()
.InstancePerDependency();
AppointmentService 有一个 InterceptAttribute。
[Intercept("log-calls")]
public class AppointmentService : IAppointmentService
...
当我调用容器的 Build() 方法时,它会抛出一个带有以下消息的 ComponentNotRegisteredException:
请求的服务“log-calls (Castle.DynamicProxy.IInterceptor)”尚未注册。为避免此异常,请注册组件以提供服务,使用 IsRegistered() 检查服务注册,或使用 ResolveOptional() 方法解决可选依赖项。
这是正确的,因为我没有实现 IInterceptor 而是 IAsyncInterceptor。我想问题是使用 ProxyGenerator 的“错误”扩展方法在 autofac 中实现 EnableInterfaceInterceptors 的具体实现 - 但我该如何解决这个问题?
干杯, 曼努埃尔
【问题讨论】:
标签: autofac castle-dynamicproxy