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 Newtonsoft.Json; using Newtonsoft.Json.Serialization; using PartSource.Data.AutoMapper; using PartSource.Data.Contexts; 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; }) .AddNewtonsoftJson(options => { options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; options.SerializerSettings.ContractResolver = new DefaultContractResolver() { NamingStrategy = new SnakeCaseNamingStrategy() }; }); 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(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddCors(o => o.AddPolicy("Default", builder => { builder.AllowAnyOrigin() .AllowAnyMethod() .AllowAnyHeader(); })); services.AddDbContext(options => options.UseSqlServer(Configuration.GetConnectionString("PartSourceDatabase")) ); //services.AddDbContext(options => // options.UseSqlServer(Configuration.GetConnectionString("FitmentDatabase")) //); } // 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(); } } }