0

Interceptionを使用して組み込みPolicyInjectionBehavior、このエラーを取得しようとしています:

例外情報: 例外の種類: ResolutionFailedException 例外メッセージ: 依存関係の解決に失敗しました。タイプ = "CSR.Presentation.Controllers.HomeController"、名前 = "(none)"。例外が発生しました: コンストラクター Microsoft.Practices.Unity.InterceptionExtension.PolicyInjectionBehavior(Microsoft.Practices.Unity.InterceptionExtension.CurrentInterceptionRequestinterceptionRequest、Microsoft.Practices.Unity.InterceptionExtension.InjectionPolicy[] ポリシー、Microsoft.Practices.Unity.IUnityContainer コンテナー) を呼び出しています。例外: ArgumentException - 渡される型はインターフェイスでなければなりません。

Interception登録でコードを除外すると、正常に動作します。のコンテナをループすると、Output Windowすべての登録がそこにあるように見えます。Interceptionまた、手動で登録してコードを含めると、それも機能します。多くのインターフェースがあり、それらを個別に登録したくありません。これが私がやっていることです-この順序で:

// FIRST
   container.RegisterTypes(
       AllClasses.FromLoadedAssemblies(), 
       WithMappings.FromMatchingInterface, 
       WithName.Default,
       WithLifetime.ContainerControlled,
         t => new InjectionMember[] { 
            new Interceptor<InterfaceInterceptor>(),
            new InterceptionBehavior<PolicyInjectionBehavior>()});

// SECOND
   container.AddNewExtension<Interception>();

// THIRD    
   var first = new InjectionProperty("Order", 1);
   var second = new InjectionProperty("Order", 2);

   container.Configure<Interception>()
       .AddPolicy("logging")
       .AddMatchingRule<NamespaceMatchingRule>(
            new InjectionConstructor(
            new InjectionParameter("CSR*")))             
       .AddCallHandler<LoggingCallHandler>(
            new ContainerControlledLifetimeManager(),
            new InjectionConstructor(),
            first);

// Controller ==> execution doesn't reach here using interception
 public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View("Index");
        }        
    }
4

0 に答える 0