[英]EnableInterfaceInterceptors not available from Autofac RegisterType
我想使用Autofac探索自定義攔截器。 我當前正在使用4.2.0版的Autofac和3.3.3版的Castle.Core用於DynamicProxy。
我從以下基本動作開始,希望在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();
}
}
問題是“ .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 assembly reference?)
到目前為止(如果相關)其他組件的代碼是:
public interface IMyInterface
{
void DoWork(string key1, string key2);
}
using System;
public class MyClassA : IMyInterface
{
public void DoWork(string key1, string key2)
{
Console.WriteLine(string.Format("A: {0} - {1}", key1, key2));
}
}
using System;
using Castle.DynamicProxy;
public class MyInterceptor : StandardInterceptor
{
protected override void PreProceed(IInvocation invocation)
{
Console.Write("PreProceed: ");
}
}
有人可以告訴我為什么.EnableInterfaceInterceptors()
不起作用嗎?
我猜您忘記了引用Autofac.Extras.DynamicProxy
程序包。 請參閱此處的文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.