Created
December 18, 2023 15:19
-
-
Save renatogroffe/11315421c9858a701f5f7c6aefa691f5 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 APIContagem; | |
using APIContagem.Middlewares; | |
using APIContagem.Models; | |
var builder = WebApplication.CreateBuilder(args); | |
builder.Services.AddEndpointsApiExplorer(); | |
builder.Services.AddSwaggerGen(); | |
builder.Services.AddSingleton<Contador>(); | |
var app = builder.Build(); | |
app.UseSwagger(); | |
app.UseSwaggerUI(); | |
app.UseHttpsRedirection(); | |
app.UseMiddlewareExecutionNotificator(); | |
app.MapGet("/status", () => | |
{ | |
app.Logger.LogInformation("Acionado endpoint de Health Check"); | |
return "API Contagem - OK"; | |
}).ShortCircuit(); | |
app.MapGet("/contador", (Contador contador) => | |
{ | |
int valorAtualContador; | |
lock (contador) | |
{ | |
contador.Incrementar(); | |
valorAtualContador = contador.ValorAtual; | |
} | |
app.Logger.LogInformation($"Contador - Valor atual: {valorAtualContador}"); | |
return TypedResults.Ok(new ResultadoContador() | |
{ | |
ValorAtual = contador.ValorAtual, | |
Local = contador.Local, | |
Kernel = contador.Kernel, | |
Framework = contador.Framework, | |
Mensagem = app.Configuration["Saudacao"] | |
}); | |
}).Produces<ResultadoContador>().WithOpenApi(); | |
app.Run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment