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 ...
随机推荐
- git pull文件时和本地文件冲突 方法之一
1.先将本地修改存储起来 2.pull内容 3.还原暂存的内容 4.解决文件中冲突的的部分 打开 dsa.txt 文件手动解决冲突. 其中Updated upstream 和=====之间的内容就是p ...
- 读micro8的一些记录与思考
最近做了一段时间的攻击,个人对于整个攻击链相对来说还是比较熟悉.看了侯师傅的文章还是学到一些,做个备忘. 1.
- 使用hbuilder打包时,调用地图和相机
<template> <div class="comCon"> <!-- 你是头部区域的内容 --> <headback class=&q ...
- 利用 Monitor.TryEnter 来规避 .NET 线程死锁的源代码
在开发多线程的应用程序时,我们会大量用到 lock (...) {} 块.如果 lock 的对象比较多,非常容易发生死锁.死锁的发生很难预料,而且一旦发生在界面线程上,界面就不再刷新响和应用户输入:如 ...
- ffmpeg生成视频封面图
ffmpeg 是一个视频处理软件 php-ffmpeg 是一个让 php 可以操作 ffmpeg 的 php插件,封装好了各种操作视频的名命令.直接调用对应的方法即可. 使用过程很曲折也很简单 曲折在 ...
- 使用 Eclipse 构建的时候会出现 run as 中没有 maven package 选项
注:该方法来自我学习时别人分享的出现问题的解决方法,并没有亲自测试,仅供参考 是因为建的是普通 java 工程,需要把它转换成 maven project. 1.右键工程--maven--Disabl ...
- cubase 反向音频处理
- less 分页显示文件内容
1.命令功能 less 是more的增强版,可以分页显示文件内容,而且less打开文件的速度要比vi,more更快.less支持搜索功能,显示行号. 2.语法格式 less option file ...
- python读取csv文件的某一列或某几列
import csvimport pandas as pd with open('D:\Data\新建文件夹\list3.2.csv','r') as csvfile: reader = csv.re ...
- 一例swoole_process运行swoole_http_server
swoole_process swoole_process('执行的文件路径','文件所需的参数');//利用swoole-process执行一个外部脚本 swoole_process__constr ...