let's think of an Interface like this:

public interface ITest
{
    void DoSomething();
}

I don't want to implement this interface, and ask Ninject to generate a proxy class implementing it. Then Intercept DoSomething method. Is it possible?

有帮助吗?

解决方案

As far as i know, out of the box ninject does not support interception proxies without an implementation (i.E. class inheriting from the interface). If you want an interface proxy with implementation only by interceptors, no class, then you could use castle.dynamicproxy "interface proxy without target" (see http://docs.castleproject.org/Tools.Kinds-of-proxy-objects.ashx), but you would have to implement the binding sugar yourself.

Alternatively you could try to use https://github.com/ninject/ninject.extensions.interception and .Bind().ToConstant(Mock.Of).Intercept().With(new SomeInterceptor);.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top