我使用 Autofac.Extras.DynamicProxy2 来实现我的 AOP 策略。
我将 Autofac.Extras.DynamicProxy2 更新到 v3.0.6,出现异常:
The component Activator = LookupService (ReflectionActivator), Services = [WordBook.Protocols.Logic.ILookupService], Lifetime = Autofac.Core.Lifetime.CurrentScopeLifetime, Sharing = None, Ownership = OwnedByLifetimeScope cannot use interface interception as it provides services that are not publicly visible interfaces. Check your registration of the component to ensure you're not enabling interception and registering it as an internal/private interface type.
这是我的源代码:
ContainerBuilder builder = new ContainerBuilder();
builder.RegisterType<ExceptionInterceptor>();
builder.RegisterAssemblyTypes(Assembly.Load("WordBookLogics")).AsImplementedInterfaces().EnableInterfaceInterceptors();
var container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
它适用于 Autofac.Extras.DynamicProxy2 v3.0.5。
更新时需要调整什么吗?
最佳答案
我想我找到了问题。
在 Autofac.Extras.DynamicProxy2 v3.0.5 中,RegistrationExtensions.cs 的第 300 行具有 IsVisible 条件。
但是,IsVisible 条件在 Autofac.Extras.DynamicProxy2 v3.0.6 中被替换为 Assembly.IsInternalToDynamicProxy()。
我的公共(public)接口(interface)的 IsVisible 属性为真,但我在我的公共(public)接口(interface)上调用 Assembly.IsInternalToDynamicProxy() 的结果为假。
因此,我的公共(public)接口(interface)是可见的,但并不意味着 dynamicproxy 内部。
这就是我的拦截不起作用并在 Autofac.Extras.DynamicProxy2 v3.0.6 中出现异常的原因。
我只等待 Autofac.Extras.DynamicProxy2 的所有者修复它。
关于c# - Autofac.Extras.DynamicProxy2 v3.0.6 出现异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31174406/