使用WCF的Ninject拦截扩展为我提供了一个“对象引用未设置为对象的实例”。错误
-
28-09-2019 - |
题
我开始使用NINEXT拦截扩展名,无法在WCF服务中使用它。借助WCF扩展,NInignt可以正常工作,正是拦截给我带来了麻烦。也许我做错了?当我尝试在内核构造函数中添加linfumodel时,它告诉我它已经加载了,所以我想这很好。
基本上,绑定上的所有拦截都打破了我的WCF服务,但是我的方法互感只是在服务上起作用(getData()在服务合同中)。
编辑:以下也不起作用:
Kernel.Intercept((request) => request.Method.Name.StartsWith("Get"))
.With<TimingInterceptor>();
结束编辑
protected override IKernel CreateKernel()
{
IKernel kernel = new StandardKernel(new ServiceModule());
//var binding = kernel.Bind<MockBroker>().ToSelf();
//binding.Intercept().With<TimingInterceptor>(); // THIS BREAKS
kernel.InterceptAfter<Watch>(m => m.GetData(0), i => { i.ReturnValue = "BLABLABLA"; log.Info("INTERCEPTED!"); }); //WORKS
//kernel.Bind<Watch>().ToSelf().Intercept().With(new TimingInterceptor()); //BREAKS
//kernel.Bind<FileSystemBroker>().ToSelf().Intercept().With<TimingInterceptor>(); //BREAKS
return kernel;
}
public class TimingInterceptor : SimpleInterceptor
{
readonly Stopwatch _stopwatch = new Stopwatch();
//private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
protected override void BeforeInvoke(IInvocation invocation)
{
_stopwatch.Start();
}
protected override void AfterInvoke(IInvocation invocation)
{
_stopwatch.Stop();
string message = string.Format("[Execution of {0} took {1}.]",
invocation.Request.Method,
_stopwatch.Elapsed);
//log.Info(message);
_stopwatch.Reset();
}
}
提前thanx
解决方案
Linfu仅支持虚拟方法拦截。将所有截取的方法更改为虚拟或切换到DynamicProxy2。
不隶属于 StackOverflow