当DBContext与瞬时作用域一起使用时,它将在使用之前被处置

问题描述

这是我要实现的代码片段

-DI重新注册

services.AddDbContext<InsurerQuotesDbContext>(options =>
           options.UsesqlServer(
               Configuration.GetConnectionString("InsurerQuotesConnection")),ServiceLifetime.Transient);
  • 构造函数

         private readonly InsurerQuotesDbContext _context;
      private readonly string appBaseUrl = MyHttpContext.AppBaseUrl;
      private readonly object _lockObject = new object();
      private readonly List<Benefit> Benefits;
    
      public FrontEndQuotesBuilder(ILookUpsService lookupsService,InsurerQuotesDbContext context)
      {
          _lookupsService = lookupsService;
          _context = context;
          Benefits = _context.Benefits.ToList();
      }
    
  • 在这里我正在使用dbContext

    var vehiclelogo = _context.VehicleMakes.FirstOrDefault(v => v.Code == requestModel.VehicleMakeCode.ToString());

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)