persistence/Persistence.API/Startup.cs
Olga Nemt 1fdd199954 1. Убран Id у DataSaub, теперь в качестве первичного ключа выступает Date
2. Автотесты для методов GetDatesRande, GetResampledData.
3. Рефакторинг
2024-11-22 15:47:00 +05:00

61 lines
1.5 KiB
C#

using Persistence.Repository;
using Persistence.Database.Model;
using Persistence.Database.Postgres;
namespace 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.AddJWTAuthentication(Configuration);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseSwagger();
app.UseSwaggerUI();
app.UseRouting();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
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<PersistenceDbContext>();
context.Database.EnsureCreatedAndMigrated();
}
}