使用Ninject Dispose的WCF未在requestscope中触发 [英] WCF using Ninject Dispose not triggering in requestscope
问题描述
这是我的模块
internal class WebServiceConfiguration : NinjectModule
{
public override void Load()
{
Bind<IWebService>().To<WebService>().InRequestScope();
}
}
这是global.asax
Here is the global.asax
public class Global : NinjectHttpApplication
{
protected override IKernel CreateKernel()
{
return new StandardKernel(new WebServiceConfiguration());
}
}
我还尝试了InScope(c => OperationContext.Current)
I also tried InScope(c => OperationContext.Current)
这是我在IWebService中具有IDisposable的服务
Here is my service with IDisposable in IWebService
[ServiceBehavior(InstanceContextMode = InstanceContextModeDefinition.Mode)]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class WebService : IWebService
{
private readonly ISomeService _someService;
public WebService(ISomeService someService)
{
_someService = someService;
}
public void Dispose()
{
_someService.Dispose();
}
这是服务标记中的ServiceHostFactory
Here is the ServiceHostFactory in the service markup
<%@ ServiceHost Language="C#" Debug="true" Factory="Ninject.Extensions.Wcf.NinjectDataServiceHostFactory" Service="WCFTest.Services.WebService" CodeBehind="WebService.svc.cs" %>
注入依赖项是可行的.我唯一担心的是,当客户端关闭服务调用时,不会触发dispose方法.
The injection of dependencies works. My only concern is that the dispose method is not being triggered when the Client closes the service call.
我试图删除Factory ="Ninject.Extensions.Wcf.NinjectDataServiceHostFactory"只是为了测试是否将调用Dipose,并且确实调用了Dipose,但是我当然不会进行自动注入.因此,可能是我在设置中做错了什么?还是ninject没有调用Dispose的错误?
I tried to remove the Factory="Ninject.Extensions.Wcf.NinjectDataServiceHostFactory" just to test if the Dipose will be called, and it did call but of course i won't have auto injection. So there might be something i'm doing wrong in the setup? or there is a bug on ninject not calling Dispose?
注意:我在ninject wcf扩展中获取了示例设置,只是添加了一些DI.
Note: I grab the sample setup in ninject wcf extension and just added some DI.
您的帮助将不胜感激.
顺便说一句:我正在使用Ninject 3.0.0.15,Ninject.Extensions.Wcf 3.0.0.5,Ninject.Web.Common 3.0.0.7
BTW: I'm using Ninject 3.0.0.15, Ninject.Extensions.Wcf 3.0.0.5, Ninject.Web.Common 3.0.0.7
推荐答案
使用
Bind<IWebService, WebService>().To<WebService>().InRequestScope();
这篇关于使用Ninject Dispose的WCF未在requestscope中触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!