Files
Partsource/PartSource.Api/Startup.cs
2020-09-02 20:53:34 -04:00

89 lines
2.3 KiB
C#

using AutoMapper;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Formatters;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using PartSource.Api.Formatters;
using PartSource.Data;
using PartSource.Data.AutoMapper;
using PartSource.Services;
using System.IO;
namespace PartSource.Api
{
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc(options =>
{
options.OutputFormatters.RemoveType(typeof(StringOutputFormatter));
options.EnableEndpointRouting = false;
});
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v2", new OpenApiInfo { Title = "Partsource/WHI Integration API", Version = "v2" });
c.IncludeXmlComments(Path.Combine(System.AppContext.BaseDirectory, "PartSource.Api.xml"));
c.IncludeXmlComments(Path.Combine(System.AppContext.BaseDirectory, "PartSource.Data.xml"));
});
services.AddAutoMapper(typeof(PartSourceProfile));
services.AddTransient<PartService>();
services.AddTransient<NexpartService>();
services.AddTransient<SecurityService>();
services.AddTransient<VehicleService>();
services.AddCors(o => o.AddPolicy("Default", builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
}));
services.AddDbContext<PartSourceContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("PartSourceDatabase"))
);
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
//else
//{
// app.UseHsts();
//}
app.UseCors("Default");
app.UseSwagger();
app.UseReDoc(c =>
{
c.SpecUrl = "/swagger/v2/swagger.json";
c.ExpandResponses(string.Empty);
});
// app.UseExceptionHandler("/Error");
// app.UseHttpsRedirection();
app.UseMvc();
}
}
}