Configuring Dbcontext as Transient

后端 未结 2 1328
借酒劲吻你
借酒劲吻你 2020-12-09 14:55

In ASP.NET Core / EntityFramework Core, the services.AddDbContext<> method will add the specified context as a scoped service. It\'s my understanding that that is the su

2条回答
  •  一个人的身影
    2020-12-09 15:32

    The lifetime is a parameter on AddDbContext<>(). See example:

    services.AddDbContext(options =>
             options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")), 
             ServiceLifetime.Transient);
    

    This will add it to the service collection with transient lifetime.

提交回复
热议问题