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 ...
随机推荐
- macbook打印出现乱码解决方案
系统偏好设置 --> 打印机与扫描仪 --> + (左下角的加号) --> IP --> 输入打印机的ip地址,然后最下面的 “使用选择” 中选中 普通PCL 打印机,(默认的 ...
- python之时间日期datetime
相比于time模块,datetime模块的接口则更直观.更容易调用datetime模块定义了以下几个类: datetime.date():表示日期的类.常用的属性是year,month,day:dat ...
- Win7自带的系统备份还原功能如何去使用?
很多用户都会反映Win7系统使用过程中会出现系统或应用程序方面的小故障,针对这些小问题,再选择进行电脑系统的重装就有些过于麻烦了. 其实Win7系统内带有系统备份和还原的功能,可以在电脑系统出现小问题 ...
- Intellij IDEA显示调用时序图插件SequenceDiagram
1 推荐一个插件SequenceDiagram可以自动生成项目调用的时序图 安装好之后重启idea即可 2 使用,找到你要查询的方法
- -sh: ./a.out: not found
感觉程序没有问题,编译生成a.out后,拷贝到开发板执行,提示 -sh: ./a.out: not found. 上网查找问题,大概原因有2个 一就是有可能/lib下面没有C库 就是没有glibc或者 ...
- java8学习之Optional深入详解
自上次[http://www.cnblogs.com/webor2006/p/8243874.html]函数式接口的学习告一段落之后,这次来学习一下Optional,它并非是函数式接口的概念,点击查看 ...
- Dijkstra 优先队列优化
#include <iostream> #include <queue> #include <vector> using namespace std; ; stru ...
- Spring 事务相关
事务类型 数据库事务类型有本地事务和分布式事务: 本地事务:就是普通事务,能保证单台数据库上的操作的ACID,被限定在一台数据库上: 分布式事务:涉及两个或多个数据库源的事务,即跨越多台同类或异类数据 ...
- 代理模式-aop
https://www.jianshu.com/p/a82509c4bb0d 在软件业,AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期 ...
- Acwing-203-同余方程(扩展欧几里得)
链接: https://www.acwing.com/problem/content/205/ 题意: 求关于x的同余方程 ax ≡ 1(mod b) 的最小正整数解. 思路: 首先:扩展欧几里得推导 ...