-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
71 lines (54 loc) · 2.22 KB
/
Program.cs
File metadata and controls
71 lines (54 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using Microsoft.OpenApi;
using Scalar.AspNetCore;
namespace WebAPI
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddControllers();
// gera o documento OpenAPI
builder.Services.AddOpenApi(options =>
{
options.AddDocumentTransformer((document, context, cancellationToken) =>
{
document.Components ??= new();
document.Components.SecuritySchemes ??= new Dictionary<string, IOpenApiSecurityScheme>();
document.Components.SecuritySchemes["Bearer"] = new OpenApiSecurityScheme
{
Type = SecuritySchemeType.Http,
Scheme = "bearer",
BearerFormat = "JWT",
In = ParameterLocation.Header,
Name = "Authorization",
Description = "Informe o token JWT: Bearer {token}"
};
return Task.CompletedTask;
});
});
var stringConexao = builder.Configuration["StringConexao"];
Environment.SetEnvironmentVariable("StringConexao", stringConexao);
// IOC
builder.Services.AddScoped<Repository.MySqlDbContext>();
builder.Services.AddScoped<Repository.CidadeRepository>();
builder.Services.AddScoped<Repository.AlunoRepository>();
builder.Services.AddScoped<Service.CidadeService>();
builder.Services.AddScoped<Service.AlunoService>();
var app = builder.Build();
// endpoint do json OpenAPI
app.MapOpenApi();
// interface visual do Scalar
app.MapScalarApiReference("/doc", options =>
{
// Design e Layout
options.WithTheme(ScalarTheme.Laserwave).WithClassicLayout();
});
// Configure the HTTP request pipeline.
app.UseAuthorization();
app.MapControllers();
app.Run();
}
}
}