2016-10-31 16:54:55 +01:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
2016-09-06 17:09:19 -07:00
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2016-10-31 16:54:55 +01:00
|
|
|
|
using Microsoft.AspNetCore.Mvc.ApiExplorer;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
|
|
|
using Microsoft.eShopOnContainers.Services.Catalog.API.Model;
|
2016-09-06 17:09:19 -07:00
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
2016-10-31 16:54:55 +01:00
|
|
|
|
using Newtonsoft.Json.Serialization;
|
|
|
|
|
using System.Threading.Tasks;
|
2016-09-06 17:09:19 -07:00
|
|
|
|
|
2016-09-07 13:52:26 -07:00
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Catalog.API
|
2016-09-06 17:09:19 -07:00
|
|
|
|
{
|
|
|
|
|
public class Startup
|
|
|
|
|
{
|
2016-10-31 16:54:55 +01:00
|
|
|
|
public IConfigurationRoot Configuration { get; }
|
|
|
|
|
|
2016-09-06 17:09:19 -07:00
|
|
|
|
public Startup(IHostingEnvironment env)
|
|
|
|
|
{
|
|
|
|
|
var builder = new ConfigurationBuilder()
|
|
|
|
|
.SetBasePath(env.ContentRootPath)
|
2016-10-31 16:54:55 +01:00
|
|
|
|
.AddJsonFile($"settings.{env.EnvironmentName}.json",optional:false)
|
2016-09-06 17:09:19 -07:00
|
|
|
|
.AddEnvironmentVariables();
|
2016-10-31 16:54:55 +01:00
|
|
|
|
|
|
|
|
|
|
2016-09-06 17:09:19 -07:00
|
|
|
|
Configuration = builder.Build();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 16:54:55 +01:00
|
|
|
|
|
2016-09-06 17:09:19 -07:00
|
|
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
2016-10-31 16:54:55 +01:00
|
|
|
|
services.AddSingleton<IConfiguration>(Configuration);
|
|
|
|
|
|
|
|
|
|
services.AddDbContext<CatalogContext>(c =>
|
|
|
|
|
{
|
2016-09-14 08:35:34 -07:00
|
|
|
|
c.UseNpgsql(Configuration["ConnectionString"]);
|
2016-10-31 16:54:55 +01:00
|
|
|
|
c.ConfigureWarnings(wb =>
|
|
|
|
|
{
|
|
|
|
|
wb.Throw(RelationalEventId.QueryClientEvaluationWarning);
|
|
|
|
|
});
|
2016-09-14 08:35:34 -07:00
|
|
|
|
});
|
|
|
|
|
|
2016-09-06 17:09:19 -07:00
|
|
|
|
// Add framework services.
|
2016-10-31 16:54:55 +01:00
|
|
|
|
|
|
|
|
|
services.AddCors();
|
|
|
|
|
|
2016-09-14 08:35:34 -07:00
|
|
|
|
services.AddMvcCore()
|
2016-10-31 16:54:55 +01:00
|
|
|
|
.AddJsonFormatters(settings=>
|
|
|
|
|
{
|
|
|
|
|
settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
|
|
|
|
|
});
|
2016-09-06 17:09:19 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
|
|
|
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
|
|
|
|
|
{
|
2016-10-31 16:54:55 +01:00
|
|
|
|
|
|
|
|
|
//Configure logs
|
|
|
|
|
|
|
|
|
|
if(env.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-06 17:09:19 -07:00
|
|
|
|
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
|
|
|
|
|
loggerFactory.AddDebug();
|
|
|
|
|
|
2016-10-31 16:54:55 +01:00
|
|
|
|
//Seed Data
|
|
|
|
|
|
|
|
|
|
CatalogContextSeed.SeedAsync(app)
|
|
|
|
|
.Wait();
|
|
|
|
|
|
|
|
|
|
// Use frameworks
|
|
|
|
|
app.UseCors(policyBuilder=>policyBuilder.AllowAnyOrigin());
|
|
|
|
|
|
2016-09-06 17:09:19 -07:00
|
|
|
|
app.UseMvc();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|