2016-11-15 12 views
0

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()」の行が赤のエラーを持っているということです次のエラーとその下の波線は:

​​

これまで(それは関連性の場合)他の構成要素にコードされ:

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()がうまく動作しないのか教えていただけますか?

答えて

2

Autofac.Extras.DynamicProxyパッケージを参照していないと思います。 See the docs here.

+0

私はDynamicProxy2が後継者であり、新しいAutofacバージョンではサポートされていないと誤って思ったのですが、これを見落としました。 Travisありがとう。 –

関連する問題