我想使用 Autofac 探索自定义拦截器。我目前正在使用 Autofac 的 4.2.0 版和用于 DynamicProxy 的 Castle.Core 的 3.3.3 版。
我从以下基本行为开始,希望在 Autofac 中使用其接口注册测试类:
using Autofac;
using Castle.DynamicProxy;
class Program
{
static void Main(string[] args)
{
ContainerBuilder builder = new ContainerBuilder();
builder.RegisterType<MyClassA>()
.As<IMyInterface>()
.EnableInterfaceInterceptors()
.InterceptedBy(typeof(MyInterceptor));
builder.RegisterType<MyInterceptor>().AsSelf();
var container = builder.Build();
}
}
Run Code Online (Sandbox Code Playgroud)
问题是“.EnableInterfaceInterceptors()”行下面有一条红色错误波浪线,并显示以下错误:
'IRegistrationBuilder<MyClassA, ConcreteReflectionActivatorData, SingleRegistrationStyle>' does not contain a definition for 'EnableInterfaceInterceptors' and no extension method 'EnableInterfaceInterceptors accepting a first argument of type 'IRegistrationBuilder<MyClassA, ConcreteReflectionActivatorData, SingleRegistrationStyleA>' could be found (are you missing a using directive or an …