0

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> ();
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 ?

Khairuddin Ni'am
  • 823
  • 1
  • 8
  • 13

1 Answers1

1

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.

Remo Gloor
  • 32,665
  • 4
  • 68
  • 98