Initial Upgrade to .NET Core 2.0 (#50)

* Ardalis/upgrade1 (#44)

* Upgrading to netcore 2.0
Updating repository to support async options and refactoring to use it.

* Starting work on tracking customer orders feature.

* Cleaning up some bugs
Working on basket view component implementation

* Fixing up styles, especially for basket in header.

* Adding Order Features (#47)

* Working on order model binding from checkout page - WIP

* Small layout tweaks (#43)

* Updating quantities implemented.

* Fixed basket widget count

* Order History (#49)

* working on creating and viewing orders.
* Working on wiring up listing of orders
* List orders page works as expected. Needed to support ThenInclude scenarios. Currently using strings.
This commit is contained in:
Steve Smith
2017-09-22 11:28:55 -04:00
committed by GitHub
parent b90bd08d11
commit aca618316a
70 changed files with 1755 additions and 513 deletions

View File

@@ -1,41 +1,35 @@
using Microsoft.eShopWeb.Services;
using ApplicationCore.Entities.OrderAggregate;
using ApplicationCore.Interfaces;
using ApplicationCore.Services;
using Infrastructure.Data;
using Infrastructure.Identity;
using Infrastructure.Logging;
using Infrastructure.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.eShopWeb.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Infrastructure.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using System;
using System.Text;
using Microsoft.AspNetCore.Http;
using ApplicationCore.Interfaces;
using Infrastructure.FileSystem;
using Infrastructure.Logging;
using Microsoft.AspNetCore.Identity;
using Web.Services;
using ApplicationCore.Services;
using Infrastructure.Data;
namespace Microsoft.eShopWeb
{
public class Startup
{
private IServiceCollection _services;
public Startup(IHostingEnvironment env)
public Startup(IConfiguration configuration)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
Configuration = configuration;
}
public IConfigurationRoot Configuration { get; }
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Requires LocalDB which can be installed with SQL Server Express 2016
@@ -46,11 +40,6 @@ namespace Microsoft.eShopWeb
{
c.UseInMemoryDatabase("Catalog");
//c.UseSqlServer(Configuration.GetConnectionString("CatalogConnection"));
c.ConfigureWarnings(wb =>
{
//By default, in this application, we don't want to have client evaluations
wb.Log(RelationalEventId.QueryClientEvaluationWarning);
});
}
catch (System.Exception ex )
{
@@ -67,21 +56,28 @@ namespace Microsoft.eShopWeb
.AddEntityFrameworkStores<AppIdentityDbContext>()
.AddDefaultTokenProviders();
services.ConfigureApplicationCookie(options =>
{
options.Cookie.HttpOnly = true;
options.ExpireTimeSpan = TimeSpan.FromHours(1);
options.LoginPath = "/Account/Signin";
options.LogoutPath = "/Account/Signout";
});
services.AddScoped(typeof(IRepository<>), typeof(EfRepository<>));
services.AddScoped(typeof(IAsyncRepository<>), typeof(EfRepository<>));
services.AddMemoryCache();
services.AddScoped<ICatalogService, CachedCatalogService>();
services.AddScoped<IBasketService, BasketService>();
services.AddScoped<IOrderService, OrderService>();
services.AddScoped<IOrderRepository, OrderRepository>();
services.AddScoped<CatalogService>();
services.Configure<CatalogSettings>(Configuration);
services.AddSingleton<IUriComposer>(new UriComposer(Configuration.Get<CatalogSettings>()));
// TODO: Remove
services.AddSingleton<IImageService, LocalFileImageService>();
services.AddScoped(typeof(IAppLogger<>), typeof(LoggerAdapter<>));
// Add memory cache services
services.AddMemoryCache();
@@ -98,25 +94,8 @@ namespace Microsoft.eShopWeb
{
app.UseDeveloperExceptionPage();
app.UseBrowserLink();
app.Map("/allservices", builder => builder.Run(async context =>
{
var sb = new StringBuilder();
sb.Append("<h1>All Services</h1>");
sb.Append("<table><thead>");
sb.Append("<tr><th>Type</th><th>Lifetime</th><th>Instance</th></tr>");
sb.Append("</thead><tbody>");
foreach (var svc in _services)
{
sb.Append("<tr>");
sb.Append($"<td>{svc.ServiceType.FullName}</td>");
sb.Append($"<td>{svc.Lifetime}</td>");
sb.Append($"<td>{svc.ImplementationType?.FullName}</td>");
sb.Append("</tr>");
}
sb.Append("</tbody></table>");
await context.Response.WriteAsync(sb.ToString());
}));
ListAllRegisteredServices(app);
app.UseDatabaseErrorPage();
}
else
{
@@ -124,20 +103,43 @@ namespace Microsoft.eShopWeb
}
app.UseStaticFiles();
app.UseIdentity();
app.UseAuthentication();
app.UseMvc();
}
private void ListAllRegisteredServices(IApplicationBuilder app)
{
app.Map("/allservices", builder => builder.Run(async context =>
{
var sb = new StringBuilder();
sb.Append("<h1>All Services</h1>");
sb.Append("<table><thead>");
sb.Append("<tr><th>Type</th><th>Lifetime</th><th>Instance</th></tr>");
sb.Append("</thead><tbody>");
foreach (var svc in _services)
{
sb.Append("<tr>");
sb.Append($"<td>{svc.ServiceType.FullName}</td>");
sb.Append($"<td>{svc.Lifetime}</td>");
sb.Append($"<td>{svc.ImplementationType?.FullName}</td>");
sb.Append("</tr>");
}
sb.Append("</tbody></table>");
await context.Response.WriteAsync(sb.ToString());
}));
}
public void ConfigureDevelopment(IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory,
UserManager<ApplicationUser> userManager)
UserManager<ApplicationUser> userManager,
CatalogContext catalogContext)
{
Configure(app, env);
//Seed Data
CatalogContextSeed.SeedAsync(app, loggerFactory)
CatalogContextSeed.SeedAsync(app, catalogContext, loggerFactory)
.Wait();
var defaultUser = new ApplicationUser { UserName = "demouser@microsoft.com", Email = "demouser@microsoft.com" };
@@ -155,17 +157,17 @@ namespace Microsoft.eShopWeb
public void ConfigureProduction(IApplicationBuilder app,
IHostingEnvironment env,
ILoggerFactory loggerFactory,
UserManager<ApplicationUser> userManager)
UserManager<ApplicationUser> userManager,
CatalogContext catalogContext)
{
Configure(app, env);
//Seed Data
CatalogContextSeed.SeedAsync(app, loggerFactory)
CatalogContextSeed.SeedAsync(app, catalogContext, loggerFactory)
.Wait();
var defaultUser = new ApplicationUser { UserName = "demouser@microsoft.com", Email = "demouser@microsoft.com" };
userManager.CreateAsync(defaultUser, "Pass@word1").Wait();
}
}
}