我正在尝试使用Ninject选择性地对类型进行拦截。如果实现实现了特定的接口,我想拦截它。如何检查Ninject Activation Context以查看其目标是否实现了接口?
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
{ }
}
答案 0 :(得分:1)
我忽略了计划属性,这似乎有效:
if (x.Plan.Type.GetInterface(typeof(IGetIntercepted).FullName) != null)
{
return true;
}