Autofac을 사용하여 사용자 지정 인터셉터를 탐색하려고합니다. 저는 현재 Autofac 버전 4.2.0과 DynamicProxy 용 Castle.Core 버전 3.3.3을 사용하고 있습니다.EnableInterfaceInterceptors를 Autofac에서 사용할 수 없음 RegisterType
것은 내가 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()
이 작동하지 않는지 말할 수 있습니까?
나는 DynamicProxy2가 후계자이고 실수로 생각한 후에 이것을 간과했으며 새로운 Autofac 버전에서는 지원되지 않습니다. 트래비스 고마워. –