The request lifetime scope cannot be created because the HttpContext is not available
2017-10-13 11:29
1001 查看
项目中应用了Autofac,在Global轮询处理Job的时候,需要获取现有得Service,而这些Service已经通过Autofac进行了配置,所以理所应当的用下面的代码去获取了。
DependencyResolver.Current.GetService<ClinicalCaseService>();
结果出现问题了,直接抛出错误“The request lifetime scope cannot be created because the HttpContext is not available”。
结果疯狂的stackoverflow(地址:https://stackoverflow.com/questions/21804857/autofac-the-request-lifetime-scope-cannot-be-created-because-the-httpcontext-i),查找解决方案。
因为在AutofacDependencyResolver.Current内部GetService的时候需要HttpContext,所以会直接抛出错误。
解决方案:
1,autofac
var resolver = new AutofacWebApiDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = resolver;
2,获取Service
ClinicalCaseService = GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof (ClinicalCaseService)) as ClinicalCaseService;
DependencyResolver.Current.GetService<ClinicalCaseService>();
结果出现问题了,直接抛出错误“The request lifetime scope cannot be created because the HttpContext is not available”。
结果疯狂的stackoverflow(地址:https://stackoverflow.com/questions/21804857/autofac-the-request-lifetime-scope-cannot-be-created-because-the-httpcontext-i),查找解决方案。
因为在AutofacDependencyResolver.Current内部GetService的时候需要HttpContext,所以会直接抛出错误。
解决方案:
1,autofac
var resolver = new AutofacWebApiDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = resolver;
2,获取Service
ClinicalCaseService = GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof (ClinicalCaseService)) as ClinicalCaseService;
相关文章推荐
- fix errors 1088: “Failed to execute request because the App-Domain could not be created. Error: 0x80070005 Access is denied” and 1334: “Exception: System.IO.FileLoadException”
- IIS不能用,报错:Failed to execute request because the App-Domain could not be created. Error: 0×80070005 Access is denied
- 在MOSS2007上加载工作流出现以下错误:“The form cannot be displayed because session state is not available”
- [转]BIZTALK: Cannot perform encryption or decryption because the secret is not available from the master secret server
- apt-get couldn't be verified because the public key is not available: NO_PUBKEY XXX
- 解决问题:The context cannot be used while the model is being created
- Failed to execute request because the App-Domain could not be created.
- The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from
- The type javax.http.HttpServletRequest cannot be resolved.It is indirectly……问题之解决
- The following signatures couldn't be verified because the public key is not available
- Failed to execute request because the App-Domain could not be created
- BIZTALK: Cannot perform encryption or decryption because the secret is not available from the master secret server
- The following signatures couldn't be verified because the public key is not available
- The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly reference 问题之解决
- asp.net2.0發佈到本機IIS報錯:Failed to execute request because the App-Domain could not be created. Error: 0×80070005 儲存被拒絕.
- The context cannot be used while the model is being created
- The type javax.servlet.http.HttpServletRequest cannot be resolved. It is indirectly referenced from required .class files
- FW:BIZTALK: Cannot perform encryption or decryption because the secret is not available from the master secret server
- Failed to execute request because the App-Domain could not be created. Error: 0×80131902的解决方法
- The server cannot or will not process the request due to something that is perceived to be a client