Intercept object created not from ninject kernel
Let say I have a class :
public class SomeClass {
public virtual void InterceptedMethod ()
{
// Do something.
}
}
I'm using Ninject
with interception extension. I want to intercept InterceptedMethod
. If I created object from ninject kernel, that method is intercepted.
kernel = InitializeKernel ();
SomeClass objectFromKernel = kernel.Get<SomeClass> ()开发者_C百科;
objectFromKernel.InterceptedMethod (); // this method is intercepted.
But, if I created object not from kernel, that method is NOT intercepted.
kernel = InitializeKernel ();
SomeClass objectSelfCreated = new SomeClass ();
objectSelfCreated.InterceptedMethod (); // this method is NOT intercepted.
Is it possible to intercept self-created object using ninject ? If possible, how can I do that ?
No Ninject can not help you in this situation. You have to create a proxy yourself or change the design so that the object is created by Ninject. See the documentation of your proxy factory about how to do this.
精彩评论