2016-02-12 46 views
0

我有一個類,我用它來引導。 作爲我按慣例使用綁定到接口的對象創建的一部分。Ninject攔截投擲錯誤。動態代理

所有工作正常,直到我嘗試添加一個攔截器。

public class ContainerBootstrapper : IDisposable 
    { 
     StandardKernel _c; 

     public ContainerBootstrapper() 
     { 
      _c =new StandardKernel(); 

      _c.Bind(b => b.FromAssembliesMatching("Facade*.*").SelectAllClasses().BindDefaultInterfaces()); 
      _c.Bind(b => b.FromAssembliesMatching("Object*.*").SelectAllClasses().BindDefaultInterfaces()); 
      _c.Bind(b => b.FromAssembliesMatching("Logger*.*").SelectAllClasses().BindDefaultInterfaces()); 

//even using the built in ActionInterceptor like this: 

_c.Intercept(c => true) 
      .With(new ActionInterceptor(invocation => 
        Console.Write(invocation.Request.Method.Name))); 

當這條線被擊中,我得到一個錯誤 - 錯誤加載Ninject組件IAdviceFactory 沒有這樣的組件已經在內核中的組件容器被註冊。

建議: 1)如果您爲KernelBase創建了自定義子類,請確保您已正確地使用 實現了AddComponents()方法。 2)確保已不經由呼叫除去從容器中的成分的removeAll()。 3)確保你不小心創建多個內核。

我在上面:

using Ninject.Extensions.Conventions; 
using Ninject.Extensions.Interception.Injection.Dynamic; 
using Ninject.Extensions.Interception.Infrastructure.Language; 
using Ninject.Extensions.Interception; 

和使用的NuGet軟件包。試了動態代理和林福。兩者都有同樣的錯誤。

任何人有任何想法嘗試? 在此先感謝。

回答

0

原來,即使我有一個參考項目做bootstrapping,我認爲所有我的dll for ninject被自動複製的情況並非如此。手動移動它們後,它工作。