开发者

Intercept object created not from ninject kernel

开发者 https://www.devze.com 2023-03-09 04:57 出处:网络
Let say I have a class : public class SomeClass { public virtual void InterceptedMethod () { // Do something.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号