Reputation: 3388
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
{ }
}
Upvotes: 1
Views: 134
Reputation: 3388
I was overlooking the Plan property, this seems to work:
if (x.Plan.Type.GetInterface(typeof(IGetIntercepted).FullName) != null)
{
return true;
}
Upvotes: 1