From 7ae197da32cbdbd3678b80587e267853c7a6621d Mon Sep 17 00:00:00 2001 From: CESARDELATORRE Date: Thu, 26 Jan 2017 16:23:49 -0800 Subject: [PATCH] Interesting comments about DI and DbContext lifetime scope --- src/Services/Ordering/Ordering.API/Startup.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index 4f2feddda..fe7046b5a 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -45,7 +45,7 @@ services.AddMvc(options => { options.Filters.Add(typeof(HttpGlobalExceptionFilter)); - }).AddControllersAsServices(); + }).AddControllersAsServices(); //Controllers are also injected thru DI services.AddEntityFrameworkSqlServer() .AddDbContext(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();