Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.
2019-07-24 11:09:15.231+08:00 LISA.Common.Utilities.LogUtil -
System.ObjectDisposedException: Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.
at Autofac.Core.Lifetime.LifetimeScope.CheckNotDisposed()
at Autofac.Core.Lifetime.LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance)
at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context, IEnumerable`1 parameters)
at LisaContainer.Resolve[T]() in C:\repository\Edenred\LISA_6.0.0.0\LISACore\LISA.CMSWeb\LISA.CMSWeb\App_Code\LisaContainer.cs:line 29
at LISA.InternalService.Client.ServiceFactory.GetFileUploadContract() in C:\repository\Edenred\LISA_6.0.0.0\LISACore\LISA.InternalService.Client\ServiceFactory.cs:line 175
at LISA.Fileupload.UploadBroker.get_Instance() in C:\repository\Edenred\LISA_6.0.0.0\LISACore\LISA.Fileupload\FileUploadBrokerFactory.cs:line 39
at LISA.Fileupload.FileUploadBrokerFactory.get_IFileUploadBroker() in C:\repository\Edenred\LISA_6.0.0.0\LISACore\LISA.Fileupload\FileUploadBrokerFactory.cs:line 27
Autofac does its session disposal through an HttpModule called Autofac.Integration.Web.ContainerDisposalModule.
You need to either
- Put your own session cleanup in a module that is run before the container disposal. This can be a problem as the order of HttpModules is not guaranteed.
OR
- Remove the Container disposal HttpModule from the web.config and do your own lifetime scope cleanup in your Application EndRequest
private void Application_EndRequest(object sender, EventArgs e)
{
ISession session = ContainerProvider.RequestLifetime.Resolve();
//cleanup transaction etc...
ContainerProvider.EndRequestLifetime();
}
OR
- Create a session manager class that is IDisposable and lifetime scoped, take your ISession as a constructor dependency and do your session cleanup when it is Disposed at the end of the lifetime.
public class SessionManager : IDisposable
{
private readonly ISession _session;
private ITransaction _transaction;
public SessionManager(ISession session)
{
_session = session;
}
public void BeginRequest()
{
_transaction = _session.BeginTransaction();
}
#region Implementation of IDisposable
///
/// Dispose will be called automatically by autofac when the lifetime ends
///
public void Dispose()
{
//commit rollback, whatever
_transaction.Commit();
}
#endregion
}
You must make sure to initialize your session manager.
protected void Application_BeginRequest(object sender, EventArgs e)
{
SessionManager manager = _containerProvider.RequestLifetime.Resolve();
manager.BeginRequest();
}
Instances cannot be resolved and nested lifetimes cannot be created from this LifetimeScope as it has already been disposed.的更多相关文章
- 摘抄JPA官方文档原文 防呆
Spring Data JPA - Reference Documentation Oliver GierkeThomas DarimontChristoph StroblMark PaluchVer ...
- Spring Data Commons 官方文档学习
Spring Data Commons 官方文档学习 -by LarryZeal Version 1.12.6.Release, 2017-07-27 为知笔记版本在这里,带格式. Table o ...
- Memory leak by misusing Autofac
Recently I’ve found out that we can easily cause a memory leaks in our .net application by improper ...
- An Autofac Lifetime Primer
Or, “Avoiding Memory Leaks in Managed Composition” Understanding lifetime can be pretty tough when y ...
- PatentTips - Object-oriented processor architecture and operating method
BACKGROUND OF THE INVENTION The present invention relates to processors and computer systems. More s ...
- 从Unity引擎过度到Unreal4引擎(最终版)
原文地址:http://demo.netfoucs.com/u011707076/article/details/44036839 前言 寒假回家到现在已经有十多天了,这些天回家不是睡就是吃....哎 ...
- springMVC源码分析--HandlerMethodArgumentResolver参数解析器(一)
HandlerMethodArgumentResolver是用来为处理器解析参数的,主要用在HandlerMethod中,每个Resolver对应一种类型的参数,其实现类特别的多. HandlerMe ...
- 简单读!spring-mvc源码之穿越http请求
相信spring-mvc这种被玩坏了的架构理念,大家都烂熟于胸了,不过还是想来扒一扒他的细节. 一个http请求,怎么样被 spring 接收,又怎样做出响应呢? 一般地,我们会配置一个 web.xm ...
- Getting Started with Django Rest Framework and AngularJS
转载自:http://blog.kevinastone.com/getting-started-with-django-rest-framework-and-angularjs.html A ReST ...
随机推荐
- js扩展Date对象的方法,格式化日期格式(prototype)
扩展:Date.prototype.format = function(format){ var o = { "M+" : this.getMonth()+1, ...
- 第六篇.文件处理之python2和3字符编码的区别
目录 python2和3字符编码的区别 一.字符编码应用之python python2和3字符编码的区别 一.字符编码应用之python 1执行python的三个阶段 python test.py 执 ...
- 怎么处理Win7电脑打开软件速度慢的情况?
很多使用Win7系统的用户都会发现这么一个问题,就是电脑在使用过一段时间后,打开一个应用软件的速度就会变慢,非常耽误时间.下面就和大家分享一个解决Win7系统应用软件打开速度慢的小技巧. Win7系统 ...
- ORA-01145: offline immediate disallowed unless media recovery enabled问题解决
ORA-01145: offline immediate disallowed unless media recovery enabled (随记,后续整理) 数据库只有在归档模式下才能够直接对数据文 ...
- (七)make menuconfig
1.make menuconfig进入图形界面后,输入 / 进行查找页面,如果输入有错,要删除前面输入的可以输入 ctrl加<--键(ctrl加回退按键)
- Perl环境安装
在我们开始学习 Perl 语言前,我们需要先安装 Perl 的执行环境. Perl 可以在以下平台下运行: Unix (Solaris, Linux, FreeBSD, AIX, HP/UX, Sun ...
- Linux :ssh sftp scp
SSH 概述 1 SSH协议,Secure Shell ,为客户提供安全的shel环境,默认端口22 OpenSSH服务 服务名称:sshd 主程序:/usr/bin/sshd /usr/bin ...
- OSI七层协议模型、TCP/IP四层模型
OSI七层协议模型 TCP/IP四层模型 首先我们梳理一下每层模型的职责: 链路层:对0和1进行分组,定义数据帧,确认主机的物理地址,传输数据: 网络层:定义IP地址,确认主机所在的网络位置,并通过I ...
- MyBatis 报错org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource
报错如下: org.apache.ibatis.exceptions.PersistenceException: ### Error opening session. Cause: java.lang ...
- NIM 1
博弈论(一):Nim游戏 重点结论:对于一个Nim游戏的局面(a1,a2,...,an),它是P-position当且仅当a1^a2^...^an=0,其中^表示位异或(xor)运算. Nim游戏是博 ...