2016-11-03 17:52:15 +01:00
|
|
|
|
namespace Microsoft.eShopOnContainers.Services.Catalog.API
|
2016-09-06 17:09:19 -07:00
|
|
|
|
{
|
2016-11-03 17:52:15 +01:00
|
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
|
|
|
using Microsoft.eShopOnContainers.Services.Catalog.API.Infrastructure;
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
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-11-03 17:52:15 +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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
|
{
|
2016-10-31 16:54:55 +01:00
|
|
|
|
services.AddSingleton<IConfiguration>(Configuration);
|
|
|
|
|
|
2016-11-03 17:52:15 +01:00
|
|
|
|
services.AddDbContext<CatalogContext>(c =>
|
2016-10-31 16:54:55 +01:00
|
|
|
|
{
|
2016-11-03 17:52:15 +01:00
|
|
|
|
c.UseSqlServer(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
|
|
|
|
|
2016-11-03 17:52:15 +01:00
|
|
|
|
services.AddSwaggerGen();
|
|
|
|
|
services.ConfigureSwaggerGen(options =>
|
|
|
|
|
{
|
|
|
|
|
options.DescribeAllEnumsAsStrings();
|
|
|
|
|
options.SingleApiVersion(new Swashbuckle.Swagger.Model.Info()
|
|
|
|
|
{
|
|
|
|
|
Title = "Values API",
|
|
|
|
|
Version = "v1",
|
|
|
|
|
Description = "An API API With Swagger for RC2",
|
|
|
|
|
TermsOfService = "None"
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2016-10-31 16:54:55 +01:00
|
|
|
|
services.AddCors();
|
|
|
|
|
|
2016-11-03 17:52:15 +01:00
|
|
|
|
services.AddMvc(mvcoptions =>
|
|
|
|
|
{
|
|
|
|
|
});
|
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
|
|
|
|
|
|
2016-11-03 17:52:15 +01:00
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
|
{
|
2016-10-31 16:54:55 +01:00
|
|
|
|
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
|
2016-11-03 17:52:15 +01:00
|
|
|
|
app.UseCors(policyBuilder => policyBuilder.AllowAnyOrigin());
|
2016-10-31 16:54:55 +01:00
|
|
|
|
|
2016-09-06 17:09:19 -07:00
|
|
|
|
app.UseMvc();
|
2016-11-03 17:52:15 +01:00
|
|
|
|
|
|
|
|
|
app.UseSwagger()
|
|
|
|
|
.UseSwaggerUi();
|
2016-09-06 17:09:19 -07:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|