-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
68 lines (59 loc) · 2.03 KB
/
Program.cs
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
using Biokudi_Backend.Application.Validators;
using Biokudi_Backend.Infrastructure.Config;
using Biokudi_Backend.Infrastructure.Config.Biokudi_Backend.Infrastructure.Config;
using Biokudi_Backend.Infrastructure.Data;
using Biokudi_Backend.UI.Middleware;
using FluentValidation;
using FluentValidation.AspNetCore;
using Microsoft.EntityFrameworkCore;
using Serilog;
var builder = WebApplication.CreateBuilder(args);
// Connection Database
builder.Services.AddDbContext<ApplicationDbContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("ConnectionString")));
DependencyInjection.ConfigureServices(builder.Services, builder.Configuration);
LoggingConfig.ConfigureServices(builder.Services, builder.Configuration);
RateLimitConfig.ConfigureRateLimiting(builder.Services);
builder.Host.UseSerilog();
builder.Services.AddMemoryCache();
builder.Services.AddCustomCors();
builder.Services.AddJwtAuthentication(builder.Configuration);
builder.Services.AddValidatorsFromAssemblyContaining<ActivityRequestDtoValidator>();
builder.Services.ConfigureResponseCompression();
builder.Services.ConfigureJsonOptions();
builder.Services.AddHttpClient();
builder.Services.AddControllers();
builder.Services.AddFluentValidationAutoValidation();
builder.Services.AddFluentValidationClientsideAdapters();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.ConfigureSwagger();
builder.Services.AddOutputCache();
var app = builder.Build();
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseReDoc(c =>
{
c.Path = "/redoc";
c.DocumentPath = "/swagger/v1/swagger.json";
});
}
app.UseHttpsRedirection();
app.UseExceptionHandling();
if (!app.Environment.IsDevelopment())
{
app.UseHsts();
}
app.UseCors("OnlyFrontend");
app.UseSerilogRequestLogging();
app.UseAuthentication();
app.UseTokenRenewal();
app.UseAuthorization();
app.UseRateLimiter();
app.UseSanitization();
app.UseResponseCompression();
app.UseOutputCache();
app.MapControllers();
app.Run();