Created
June 3, 2020 17:56
-
-
Save thomascristanis/f80bd2ff12badc8edf5446b3d457a0fb to your computer and use it in GitHub Desktop.
Startup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using CoronaAPI.Data; | |
using CoronaAPI.Data.Repository; | |
using CoronaAPI.src.Data.UoW; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
namespace CoronaAPI | |
{ | |
public class Startup | |
{ | |
public Startup(IConfiguration configuration) | |
{ | |
this.Configuration = configuration; | |
} | |
public IConfiguration Configuration { get; } | |
public Startup(IHostEnvironment env) | |
{ | |
var builder = new ConfigurationBuilder() | |
.SetBasePath(env.ContentRootPath) | |
.AddJsonFile("appsettings.json", true, true); | |
builder.AddEnvironmentVariables(); | |
Configuration = builder.Build(); | |
} | |
// This method gets called by the runtime. Use this method to add services to the container. | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddControllers(); | |
services.AddTransient<IRepository<ConfigurationSystem>, ConfigurationRepository>(); | |
services.AddTransient<IUnitOfWork, UnitOfWork>(); | |
// Register the Swagger generator | |
services.AddSwaggerGen(c => | |
{ | |
c.SwaggerDoc("v1", | |
new Microsoft.OpenApi.Models.OpenApiInfo | |
{ | |
Title = "API Covid-19", | |
Version = "v1", | |
Description = "API de dados do COVID-19 extraído do Ministério da Saúde", | |
Contact = new Microsoft.OpenApi.Models.OpenApiContact | |
{ | |
Name = "Thomas Cristanis", | |
Url = new Uri("http://github.com/thomascristanis") | |
} | |
}); | |
}); | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
app.UseSwagger(); | |
app.UseSwaggerUI(c => | |
{ | |
c.SwaggerEndpoint("/swagger/v1/swagger.json", "API Covid-19"); | |
}); | |
app.UseHttpsRedirection(); | |
app.UseRouting(); | |
app.UseAuthorization(); | |
app.UseEndpoints(endpoints => | |
{ | |
endpoints.MapControllers(); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment