문제

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