内核的组件容器中尚未注册此类组件

4 c# aop ninject

考虑这个代码:

public class IocConfig
{
    protected static StandardKernel Kernel { get; set; }

    public static void RegisterIoc(HttpConfiguration config)
    {
        using (IKernel kernel = new StandardKernel())
        {
            RegisterDependency();
            config.DependencyResolver = new NinjectDependencyResolver(kernel);
        }

    }

    public static void RegisterIoc()
    {

        RegisterDependency();
    }

    private static void RegisterDependency()
    {
        if (Kernel == null)
        {
            Kernel = new StandardKernel();
        }
        Kernel.Bind<CallCenterLogger>().ToSelf().Intercept().With(new TimingInterceptor());
    }

    public static T GetType<T>()
    {
        RegisterDependency();
        return Kernel.Get<T>();
    }
}
Run Code Online (Sandbox Code Playgroud)

在这一行:

        Kernel.Bind<CallCenterLogger>().ToSelf().Intercept().With(new TimingInterceptor());
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

加载 Ninject 组件 IAdviceFactory 时出错

内核的组件容器中尚未注册此类组件。

建议:

1) 如果您已经为 KernelBase 创建了自定义子类,请确保您已正确

 implemented the AddComponents() method.
Run Code Online (Sandbox Code Playgroud)

2) 确保您没有通过调用 RemoveAll() 从容器中删除组件。

3) 确保您没有意外创建多个内核。

怎么解决?

Rem*_*oor 5

很可能你已经添加了Ninject.Extensions.Interception但没有添加任何具体的实现Ninject.Extensions.Interception, DynamicProxyNinject.Extensions.Interception,LinFu