加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

Instances cannot be resolved and nested lifetimes cannot be

发布时间:2020-12-13 23:16:23 所属栏目:Linux 来源:网络整理
导读: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.Life

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,IEnumerable`1 parameters)
at Autofac.ResolutionExtensions.Resolve[TService](IComponentContext context,IEnumerable`1 parameters)
at LisaContainer.Resolve[T]() in C:repositoryEdenredLISA_6.0.0.0LISACoreLISA.CMSWebLISA.CMSWebApp_CodeLisaContainer.cs:line 29
at LISA.InternalService.Client.ServiceFactory.GetFileUploadContract() in C:repositoryEdenredLISA_6.0.0.0LISACoreLISA.InternalService.ClientServiceFactory.cs:line 175
at LISA.Fileupload.UploadBroker.get_Instance() in C:repositoryEdenredLISA_6.0.0.0LISACoreLISA.FileuploadFileUploadBrokerFactory.cs:line 39
at LISA.Fileupload.FileUploadBrokerFactory.get_IFileUploadBroker() in C:repositoryEdenredLISA_6.0.0.0LISACoreLISA.FileuploadFileUploadBrokerFactory.cs:line 27

?

?

autofac with asp.net webforms Instances cannot be resolved and nested lifetimes cannot be

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();
    }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读