我一直在使用 Ninject 2 并更新到 Ninject 3 以更好地支持 SignalR 和其他框架。
下面的代码过去可以正常工作。
public class AttributeDrivenPlanningStrategy<TAttribute, TInterceptor> : NinjectComponent, IPlanningStrategy
where TAttribute : Attribute
where TInterceptor : IInterceptor
{
private readonly IAdviceFactory adviceFactory;
private readonly IAdviceRegistry adviceRegistry;
public AttributeDrivenPlanningStrategy(IAdviceFactory adviceFactory, IAdviceRegistry adviceRegistry)
{
this.adviceFactory = adviceFactory;
this.adviceRegistry = adviceRegistry;
}
public void Execute(IPlan plan)
{
var methods = GetCandidateMethods(plan.Type);
foreach (var method in methods)
{
if(!method.HasAttribute<TAttribute>())
{ continue; }
var advice = adviceFactory.Create(method);
advice.Callback = request => request.Kernel.Get<TInterceptor>();
adviceRegistry.Register(advice);
if (!plan.Has<ProxyDirective>())
{ plan.Add(new ProxyDirective()); }
}
}
private static IEnumerable<MethodInfo> GetCandidateMethods(Type type)
{
const BindingFlags methodFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;
var methods = type.GetMethods(methodFlags);
return methods.Where(ShouldIntercept);
}
private static bool ShouldIntercept(MethodInfo methodInfo)
{
return methodInfo.DeclaringType != typeof (object) &&
!methodInfo.IsPrivate &&
!methodInfo.IsFinal;
}
}
但是现在它爆炸说它在 ninject 绑定中找不到 IAdviceFactory,因此最新版本的拦截器中是否有任何重大更改,因为几乎没有关于此扩展的文档(考虑到数量我觉得很奇怪AoP 这些天在四处飘荡)。
那么有人能指出我某个地方的方向,它会告诉我问题是什么吗?