persistence/DD.Persistence.API/Startup.cs
Оля Бизюкова 6593acbc20
Some checks failed
Unit tests / test (push) Failing after 1m1s
Новая фабрика рефит-клиентов (RefitClientFactory).
Работает пока только для ChangeLog
2024-12-26 13:42:14 +05:00

68 lines
1.7 KiB
C#

using DD.Persistence.Database.Model;
using DD.Persistence.Database.Postgres;
using DD.Persistence.Repository;
using DD.Persistence.Client;
namespace DD.Persistence.API;
public class Startup
{
public IConfiguration Configuration { get; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public void ConfigureServices(IServiceCollection services)
{
// Add services to the container.
services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
services.AddEndpointsApiExplorer();
services.AddSwagger(Configuration);
services.AddInfrastructure();
services.AddPersistenceDbContext(Configuration);
services.AddAuthorization();
services.AddJWTAuthentication(Configuration);
services.AddMemoryCache();
services.AddServices();
services.AddPersistenceClients();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseRouting();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
}
public static void BeforeRunHandler(IHost host)
{
using var scope = host.Services.CreateScope();
var provider = scope.ServiceProvider;
var context = provider.GetRequiredService<PersistencePostgresContext>();
context.Database.EnsureCreatedAndMigrated();
}
}