Interesting comments about DI and DbContext lifetime scope
This commit is contained in:
parent
fa6a273a33
commit
7ae197da32
@ -45,7 +45,7 @@
|
||||
services.AddMvc(options =>
|
||||
{
|
||||
options.Filters.Add(typeof(HttpGlobalExceptionFilter));
|
||||
}).AddControllersAsServices();
|
||||
}).AddControllersAsServices(); //Controllers are also injected thru DI
|
||||
|
||||
services.AddEntityFrameworkSqlServer()
|
||||
.AddDbContext<OrderingContext>(options =>
|
||||
@ -53,7 +53,7 @@
|
||||
options.UseSqlServer(Configuration["ConnectionString"],
|
||||
sqlop => sqlop.MigrationsAssembly(typeof(Startup).GetTypeInfo().Assembly.GetName().Name));
|
||||
},
|
||||
ServiceLifetime.Scoped
|
||||
ServiceLifetime.Scoped //DbContext is shared across the HTTP request scope (graph of objects started in the HTTP request)
|
||||
);
|
||||
|
||||
services.AddSwaggerGen();
|
||||
|
Loading…
x
Reference in New Issue
Block a user