@@ -23,8 +23,15 @@ public Startup(IHostingEnvironment env)
2323 var builder = new ConfigurationBuilder ( )
2424 . SetBasePath ( env . ContentRootPath )
2525 . AddJsonFile ( "appsettings.json" , optional : true , reloadOnChange : true )
26- . AddJsonFile ( $ "appsettings.{ env . EnvironmentName } .json", optional : true )
27- . AddEnvironmentVariables ( ) ;
26+ . AddJsonFile ( $ "appsettings.{ env . EnvironmentName } .json", optional : true ) ;
27+
28+ if ( env . IsDevelopment ( ) )
29+ {
30+ builder . AddUserSecrets ( ) ;
31+ }
32+
33+ builder . AddEnvironmentVariables ( ) ;
34+
2835 Configuration = builder . Build ( ) ;
2936 }
3037
@@ -37,28 +44,14 @@ public void ConfigureServices(IServiceCollection services)
3744 // Add framework services.
3845 services . AddMvc ( ) ;
3946
40- //Add EF Core Context (UnitOfWork)
41- //SQL LocalDB
42- // var connString = @"Server=(localdb)\mssqllocaldb;Database=Microsoft.eShopOnContainers.Services.OrderingDb;Trusted_Connection=True;";
43-
44- //SQL SERVER on-premises
45- //(Integrated Security)
46- //var connString = @"Server=CESARDLBOOKVHD;Database=Microsoft.eShopOnContainers.Services.OrderingDb;Trusted_Connection=True;";
47-
48- //(SQL Server Authentication)
49- //var connString = @"Server=10.0.75.1;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;";
50-
47+
5148 var connString = Configuration [ "ConnectionString" ] ;
5249
53- //(CDLTLL) To use only for EF Migrations
54- //connString = @"Server=10.0.75.1;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;";
55-
56- services . AddDbContext < OrderingDbContext > ( options => options . UseSqlServer ( connString )
57- . UseSqlServer ( connString , b => b . MigrationsAssembly ( "Ordering.API" ) )
58- //(CDLTLL) MigrationsAssembly will be Ordering.SqlData, but when supported
59- //Standard Library 1.6 by "Microsoft.EntityFrameworkCore.Tools"
60- //Version "1.0.0-preview2-final" just supports .NET Core
61- ) ;
50+ services . AddDbContext < OrderingDbContext > ( options =>
51+ {
52+ options . UseSqlServer ( connString )
53+ . UseSqlServer ( connString , b => b . MigrationsAssembly ( "Ordering.API" ) ) ;
54+ } ) ;
6255
6356 services . AddTransient < IOrderRepository , OrderRepository > ( ) ;
6457 services . AddTransient < IOrderdingQueries , OrderingQueries > ( ) ;
@@ -70,9 +63,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerF
7063 loggerFactory . AddConsole ( Configuration . GetSection ( "Logging" ) ) ;
7164 loggerFactory . AddDebug ( ) ;
7265
73- //if (env.IsDevelopment())
66+ if ( env . IsDevelopment ( ) )
67+ {
7468 app . UseDeveloperExceptionPage ( ) ;
75-
69+ }
70+
7671 app . UseMvc ( ) ;
7772 }
7873 }
0 commit comments