1

I am trying to selectively use interception on types using Ninject. If an implementation implements a specific interface I want to intercept it. How can I check a Ninject Activation Context to see if its target implements an interface?

public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();

        var kernal = new StandardKernel();
        kernal.Bind<IFoo>().To<Foo>();

        kernal.Intercept(x =>
        {
            if (x is an IGetIntercepted)
            {
                return true;
            }
            return false;
        });
    }

    public interface IGetIntercepted
    { }

    public interface IFoo
    { }

    public class Foo : IFoo, IGetIntercepted
    { }
}
  • Note in this example I want to check Foo, not IFoo. (IFoo is easily found in the Ninject.Activation.Binding.Service property)
Eric Scherrer
  • 3,328
  • 1
  • 19
  • 34

1 Answers1

1

I was overlooking the Plan property, this seems to work:

if (x.Plan.Type.GetInterface(typeof(IGetIntercepted).FullName) != null)
{
    return true;
}
Eric Scherrer
  • 3,328
  • 1
  • 19
  • 34