Base solution for your next web application
Open Closed

GetAllIncluding giving exception in Hangfire job. #7369


User avatar
0
Mazharmig created

Hi, GetAllIncluding gives exception "Cannot access disposed object..." in hangfire background job.


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

    Your DbContext might have been disposed! The reason for that can be lack of UnitOfWork. Show your background job file.

  • User Avatar
    0
    maliming created
    Support Team

    Very similar: https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3873

  • User Avatar
    0
    Mazharmig created

    [UnitOfWork] //Added but not working public void InitiateNewWorkflow(int requestMainId, int requestTypeId) { var initialRequestConfiguration = _requestTypeConfigurationRepository.GetAllIncluding(p => p.InitialState).Where(p => p.RequestTypeId == requestTypeId);

    ...other code
    

    }

    // calling... var jobId = BackgroundJob.Enqueue(() => _workflowManager.InitiateNewWorkflow(requestMainId, requestTypeId.Value));

    I have added [UnitOfWork] but its not working.

  • User Avatar
    0
    maliming created
    Support Team

    You can create a unit of work inside the InitiateNewWorkflow method.

    using (var uow = _unitOfWorkManager.Begin())
    {
    	var initialRequestConfiguration = _requestTypeConfigurationRepository.GetAllIncluding(p => p.InitialState).Where(p => p.RequestTypeId == requestTypeId);
    	...other code
    }