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.的更多相关文章

  1. 摘抄JPA官方文档原文 防呆

    Spring Data JPA - Reference Documentation Oliver GierkeThomas DarimontChristoph StroblMark PaluchVer ...

  2. Spring Data Commons 官方文档学习

    Spring Data Commons 官方文档学习   -by LarryZeal Version 1.12.6.Release, 2017-07-27 为知笔记版本在这里,带格式. Table o ...

  3. Memory leak by misusing Autofac

    Recently I’ve found out that we can easily cause a memory leaks in our .net application by improper ...

  4. An Autofac Lifetime Primer

    Or, “Avoiding Memory Leaks in Managed Composition” Understanding lifetime can be pretty tough when y ...

  5. PatentTips - Object-oriented processor architecture and operating method

    BACKGROUND OF THE INVENTION The present invention relates to processors and computer systems. More s ...

  6. 从Unity引擎过度到Unreal4引擎(最终版)

    原文地址:http://demo.netfoucs.com/u011707076/article/details/44036839 前言 寒假回家到现在已经有十多天了,这些天回家不是睡就是吃....哎 ...

  7. springMVC源码分析--HandlerMethodArgumentResolver参数解析器(一)

    HandlerMethodArgumentResolver是用来为处理器解析参数的,主要用在HandlerMethod中,每个Resolver对应一种类型的参数,其实现类特别的多. HandlerMe ...

  8. 简单读!spring-mvc源码之穿越http请求

    相信spring-mvc这种被玩坏了的架构理念,大家都烂熟于胸了,不过还是想来扒一扒他的细节. 一个http请求,怎么样被 spring 接收,又怎样做出响应呢? 一般地,我们会配置一个 web.xm ...

  9. Getting Started with Django Rest Framework and AngularJS

    转载自:http://blog.kevinastone.com/getting-started-with-django-rest-framework-and-angularjs.html A ReST ...

随机推荐

  1. R安装包的问题

    package 'tswge' is not available (for R version 3.5.1) install.packages('tswge', repos="http:// ...

  2. python制作一个简单词云

    首先需要安装三个包:# 安装:pip install matplotlib# 安装:pip install jieba# 安装pip install wordcloud 1.制作英文字母的词云 效果图 ...

  3. java_day10_多线程

    第十章:线程 1.进程和线程的概述 1)进程和线程定义 进程是具有一定独立功能的程序关于某个数据集合上的一次运行活动,进程是系统进行资源分配和调度的一个独立单位. 线程是进程的一个实体,是CPU调度和 ...

  4. idea管理tomcat

    第一步,打开idea的文件——>设置——选择Application Servers: 第二步,点击+号,下拉选择Tomcat Server: 如果已经配置了环境变量CATALINA_HOME,也 ...

  5. Sereja and Brackets CodeForces - 380C (树状数组+离线)

    Sereja and Brackets 题目链接: CodeForces - 380C Sereja has a bracket sequence s1, s2, ..., *s**n, or, in ...

  6. datax部署

    1.下载: https://github.com/alibaba/DataX Clone or download下载源码,拉到下面 Quick Start Download DataX下载地址 下载安 ...

  7. UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd0 in position 0: invalid continuation byte

    用pandas打开csv文件可能会出现这种情况,原因可能是excel自己新建一个*.csv文件时候容易出错.进入文件另存为,然后选择csv文件即可.

  8. Nginx location模块整理

    location模块 Nginx location location 指令的作用是根据用户请求的URI来执行不同的应用,URI就是根据用户请求到的网址URL进行匹配,匹配成功了进行相关的操作. loc ...

  9. PassengerNginxdebian快速部署Rails

    Passenger/Nginx/Debian快速部署Rails   PassengerNginxdebian快速部署Rails     安装所需的linux包 sudo apt-get install ...

  10. Python模拟浏览器多窗口切换

    # 模拟浏览器多窗口切换 # 代码中引入selenium版本为:3.4.3 # 通过Chrom浏览器访问发起请求 # Chrom版本:59 ,chromdriver:2.3 # 需要对应版本的Chro ...