90 lines
2.8 KiB
C#
Raw Normal View History

2016-11-03 17:52:15 +01:00
namespace Microsoft.eShopOnContainers.Services.Catalog.API
{
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;
public class Startup
{
public IConfigurationRoot Configuration { get; }
public Startup(IHostingEnvironment env)
{
var builder = new ConfigurationBuilder()
.SetBasePath(env.ContentRootPath)
.AddJsonFile($"settings.json", optional: false, reloadOnChange: true)
2016-11-14 16:01:14 +01:00
.AddJsonFile($"settings.{env.EnvironmentName}.json", optional: true)
.AddEnvironmentVariables();
Configuration = builder.Build();
}
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IConfiguration>(Configuration);
2016-11-03 17:52:15 +01:00
services.AddDbContext<CatalogContext>(c =>
{
2016-11-03 17:52:15 +01:00
c.UseSqlServer(Configuration["ConnectionString"]);
c.ConfigureWarnings(wb =>
{
//By default, in this application, we don't want to have client evaluations
wb.Log(RelationalEventId.QueryClientEvaluationWarning);
});
});
// Add framework services.
2016-11-03 17:52:15 +01:00
services.AddSwaggerGen();
services.ConfigureSwaggerGen(options =>
{
options.DescribeAllEnumsAsStrings();
options.SingleApiVersion(new Swashbuckle.Swagger.Model.Info()
{
Title = "Catalog HTTP API",
2016-11-03 17:52:15 +01:00
Version = "v1",
Description = "The Catalog Service HTTP API",
TermsOfService = "Terms Of Service"
2016-11-03 17:52:15 +01:00
});
});
services.AddCors();
2016-11-03 17:52:15 +01:00
services.AddMvc(mvcoptions =>
{
});
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//Configure logs
2016-11-03 17:52:15 +01:00
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
//Seed Data
CatalogContextSeed.SeedAsync(app)
.Wait();
// Use frameworks
2016-11-03 17:52:15 +01:00
app.UseCors(policyBuilder => policyBuilder.AllowAnyOrigin());
app.UseMvc();
2016-11-03 17:52:15 +01:00
app.UseSwagger()
.UseSwaggerUi();
}
}
}