Browse Source

Interesting comments about DI and DbContext lifetime scope

pull/49/merge
CESARDELATORRE 8 years ago
parent
commit
7ae197da32
1 changed files with 2 additions and 2 deletions
  1. +2
    -2
      src/Services/Ordering/Ordering.API/Startup.cs

+ 2
- 2
src/Services/Ordering/Ordering.API/Startup.cs View File

@ -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…
Cancel
Save