使用 WCF 的 Ninject 拦截扩展给了我一个“对象引用未设置到对象实例”。错误
我正在开始使用 Ninject 拦截扩展,但无法让它在我的 WCF 服务中工作。使用 WCF 扩展,ninject 工作正常,但拦截给我带来了麻烦。也许我做错了?当我尝试在内核构造函数中添加 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();
}
}
提前感谢, 林泽
I'm getting started with the Ninject interception extension and can't get it to work in my WCF service. With the WCF extension, ninject works fine, it's the interception that's giving me trouble. Maybe i'm doing it wrong? When I try to add the LinFuModel in the kernel constructor it tells me it's already loaded, so I guess that's good.
Basically all interception on the binding breaks my wcf service, but my methodinterception just works on the service (getData() is in the service contract).
edit: the following also doesn't work:
Kernel.Intercept((request) => request.Method.Name.StartsWith("Get"))
.With<TimingInterceptor>();
end edit
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 in advance,
Rinze
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LinFu仅支持虚方法拦截。将所有拦截的方法更改为virtual或切换到DynamicProxy2。
LinFu supports only virtual method interception. Change all intercepted methods to virtual or switch to DynamicProxy2.