Minor refactoring and review on ordering bc

This commit is contained in:
Unai 2016-11-21 10:02:52 +01:00
parent 141a9a2246
commit b0cc1a14d7
2 changed files with 20 additions and 24 deletions

View File

@ -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<OrderingDbContext>(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<OrderingDbContext>(options =>
{
options.UseSqlServer(connString)
.UseSqlServer(connString, b => b.MigrationsAssembly("Ordering.API"));
});
services.AddTransient<IOrderRepository, OrderRepository>();
services.AddTransient<IOrderdingQueries, OrderingQueries>();
@ -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();
}
}

View File

@ -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",