Interception with Ninject. Fails to load IProxyRequestFactory

大憨熊 提交于 2019-12-04 08:00:58

OK, I was finally able to reproduce (forgot to make the MyClass methods virtual). The way I solved it was by removing the using block from around the kernel:

    static void Main(string[] args)
    {
        MyClass o = null;

        var kernel = new StandardKernel();
        kernel.Bind<MyClass>().ToSelf().Intercept().With(new MyInterceptor());
        o = kernel.Get<MyClass>();

        o.Echo("Hello World!"); // Error
        o.Double(5);
        Console.ReadKey(true);
    }

The reason I'm guessing this works is because under the covers it creates a proxy class for MyClass and somehow passes in the IKernel to the proxy. When you invoke the method (on the proxy) it goes back to the kernel and resolves some additional dependencies (including the IProxyRequestFactory). Since you were disposing of it, it was no longer able to resolve that dependency.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!