Pregunta

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?

¿Fue útil?

Solución

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);.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top