Created
January 22, 2017 20:26
-
-
Save renatogroffe/854e6a39323d8f5ad789a43f1c9e1622 to your computer and use it in GitHub Desktop.
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.IO; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Logging; | |
using Microsoft.Extensions.PlatformAbstractions; | |
using Swashbuckle.Swagger.Model; | |
namespace TesteAPIREST | |
{ | |
public class Startup | |
{ | |
public Startup(IHostingEnvironment env) | |
{ | |
var builder = new ConfigurationBuilder() | |
.SetBasePath(env.ContentRootPath) | |
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) | |
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) | |
.AddEnvironmentVariables(); | |
Configuration = builder.Build(); | |
} | |
public IConfigurationRoot Configuration { get; } | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc(); | |
// Configurando o serviço de documentação do Swagger | |
services.AddSwaggerGen(); | |
services.ConfigureSwaggerGen(options => | |
{ | |
options.SingleApiVersion(new Info | |
{ | |
Version = "v1", | |
Title = "Conversor de Alturas", | |
Description = "Exemplo de API REST criada com o ASP.NET Core", | |
Contact = new Contact { Name = "Renato Groffe", Url = "http://renatogroffe.net" } | |
}); | |
string caminhoAplicacao = | |
PlatformServices.Default.Application.ApplicationBasePath; | |
string nomeAplicacao = | |
PlatformServices.Default.Application.ApplicationName; | |
string caminhoXmlDoc = | |
Path.Combine(caminhoAplicacao, $"{nomeAplicacao}.xml"); | |
options.IncludeXmlComments(caminhoXmlDoc); | |
}); | |
} | |
public void Configure( | |
IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) | |
{ | |
loggerFactory.AddConsole(Configuration.GetSection("Logging")); | |
loggerFactory.AddDebug(); | |
app.UseMvc(); | |
app.UseMvcWithDefaultRoute(); | |
// Ativando middlewares para uso do Swagger | |
app.UseSwagger(); | |
app.UseSwaggerUi(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment