Open Closed

ObjectDisposedException when UnitOfWork disable #740


User avatar
0
alper created
Support Team Director
Cannot access a disposed context instance. A common cause of this error is disposing a context instance that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling 'Dispose' on the context instance, or wrapping it in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.
Object name: XXXX

System.ObjectDisposedException: Cannot access a disposed context instance. A common cause of this error is disposing a context instance that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling 'Dispose' on the context instance, or wrapping it in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.
Object name: 'WebPlatformDbContext'.

@jackmcelhinney asks here


2 Answer(s)
  • User Avatar
    0
    alper created
    Support Team Director

    let us check it. subscribe the question to get email notification

  • User Avatar
    0
    alper created
    Support Team Director

    According to the framework rules, you cannot disable the UnitOfwork pipeline. The only reason to disable the UnitOfWork is managing the UnitOfWork on your own with IUnitOfWorkManager with the following code

     using (var uow = _unitOfWorkManager.Begin(requiresNew: true, isTransactional: false ))
     {
            //.....
            await uow.CompleteAsync();
     }
    

    You might want to disable transaction for the corresponding method. To do this basically add the following attribute

    [UnitOfWork(isTransactional: false)]
    

    If you really want to disable the UnitOfWork, you can use FindAsync() instead of FirstOrDefaultAsync()


    Related document https://docs.abp.io/en/abp/latest/Unit-Of-Work

Made with ❤️ on ABP v9.1.0-preview. Updated on November 11, 2024, 11:11