From b0cc1a14d7f3ab8d7436d82413f215252f8e10b6 Mon Sep 17 00:00:00 2001 From: Unai Date: Mon, 21 Nov 2016 10:02:52 +0100 Subject: [PATCH] Minor refactoring and review on ordering bc --- src/Services/Ordering/Ordering.API/Startup.cs | 43 ++++++++----------- .../Ordering/Ordering.API/project.json | 1 + 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index 605bcdd59..8e003d8e5 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -23,8 +23,15 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API var builder = new ConfigurationBuilder() .SetBasePath(env.ContentRootPath) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) - .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) - .AddEnvironmentVariables(); + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true); + + if (env.IsDevelopment()) + { + builder.AddUserSecrets(); + } + + builder.AddEnvironmentVariables(); + Configuration = builder.Build(); } @@ -37,28 +44,14 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API // Add framework services. services.AddMvc(); - //Add EF Core Context (UnitOfWork) - //SQL LocalDB - // var connString = @"Server=(localdb)\mssqllocaldb;Database=Microsoft.eShopOnContainers.Services.OrderingDb;Trusted_Connection=True;"; - - //SQL SERVER on-premises - //(Integrated Security) - //var connString = @"Server=CESARDLBOOKVHD;Database=Microsoft.eShopOnContainers.Services.OrderingDb;Trusted_Connection=True;"; - - //(SQL Server Authentication) - //var connString = @"Server=10.0.75.1;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;"; - + var connString = Configuration["ConnectionString"]; - //(CDLTLL) To use only for EF Migrations - //connString = @"Server=10.0.75.1;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;"; - - services.AddDbContext(options => options.UseSqlServer(connString) - .UseSqlServer(connString, b => b.MigrationsAssembly("Ordering.API")) - //(CDLTLL) MigrationsAssembly will be Ordering.SqlData, but when supported - //Standard Library 1.6 by "Microsoft.EntityFrameworkCore.Tools" - //Version "1.0.0-preview2-final" just supports .NET Core - ); + services.AddDbContext(options => + { + options.UseSqlServer(connString) + .UseSqlServer(connString, b => b.MigrationsAssembly("Ordering.API")); + }); services.AddTransient(); services.AddTransient(); @@ -70,9 +63,11 @@ namespace Microsoft.eShopOnContainers.Services.Ordering.API loggerFactory.AddConsole(Configuration.GetSection("Logging")); loggerFactory.AddDebug(); - //if (env.IsDevelopment()) + if (env.IsDevelopment()) + { app.UseDeveloperExceptionPage(); - + } + app.UseMvc(); } } diff --git a/src/Services/Ordering/Ordering.API/project.json b/src/Services/Ordering/Ordering.API/project.json index c330c3657..d5b415b26 100644 --- a/src/Services/Ordering/Ordering.API/project.json +++ b/src/Services/Ordering/Ordering.API/project.json @@ -9,6 +9,7 @@ "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", + "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Logging": "1.0.0", "Microsoft.Extensions.Logging.Console": "1.0.0",