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. js多语言切换demo

    网站为了国际化的需要,会使用到语言包,案例如下图. 这次尝试用js来打语言包,用到了插件 jquery.i18n.properties ,很明显,使用这个插件需要先加载jquery. 代码布局结构   ...

  2. 1 sql server 中merge的用法

    MERGE 要更新的表名 AS target USING ( 这里是用什么数据源来跟新 ) AS source ( 这里是数据源的所有列名 ) ON 这里是要更新的表和数据源的匹配条件 WHEN MA ...

  3. Django框架——forms.ModelForm使用

    使用模型创建表单 django提供了这种简便的方式,使用方法如下: 1.在项目的一个app目录中,创建forms.py文件 2.导入模块: from django import forms from ...

  4. Swift 函数式数据结构 - 链表

    本文将使用Swift实现一个标准链表,在实现的过程中,遵守函数式编程的规则,无副作用,可以看到和C语言的实现还是有较大的差异. 预备知识 enum 的各种用法 swift的基本的模式匹配( patte ...

  5. 【计算机网络】网络地址转换NAT

    网络地址转换NAT 要知道到每个IP使能的设备都需要一个IP地址.以一个家庭为例,假设当地的ISP已为该家庭分配过一块地址,但是后期家庭中的智能设备增加(智能手机.电脑等),这些都需要IP地址才可上网 ...

  6. CA认证和证书

    一些概念: PKI:Public Key Infrastructure 签证机构:CA(Certificate Authority) 注册机构:RA(Register Authority) 证书吊销列 ...

  7. SSM框架中使用日志框架

    在 pom,xml 配置 Log4j jar 添加一个 mybatis_log.xml 文件 完整配置信息 <?xml version="1.0" encoding=&quo ...

  8. 转:ubuntu添加用户adduser,并给予sudo权限

    ubuntu添加用户adduser,并给予sudo权限 如何创建ubuntu新用户? 首先打开终端,输入:sudo adduser username正在添加用户“username”... 正在添加新组 ...

  9. 一例tornado框架下处理上传图片并生成缩略图的例子

    class coachpic(RequestHandler): @gen.coroutine def post(self): picurl = self.request.files[] print(& ...

  10. Acwing-197-阶乘分解(质数)

    链接: https://www.acwing.com/problem/content/199/ 题意: 给定整数 N ,试把阶乘 N! 分解质因数,按照算术基本定理的形式输出分解结果中的 pi 和 c ...