2024-11-14 15:17:43 +05:00
|
|
|
|
using Persistence.Repository;
|
2024-11-15 16:29:15 +05:00
|
|
|
|
using Persistence.Database.Model;
|
|
|
|
|
using Persistence.Database.Postgres;
|
2024-11-14 15:17:43 +05:00
|
|
|
|
|
|
|
|
|
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();
|
2024-11-20 15:22:23 +05:00
|
|
|
|
services.AddSwagger(Configuration);
|
2024-11-15 16:29:15 +05:00
|
|
|
|
services.AddInfrastructure();
|
2024-11-20 15:22:23 +05:00
|
|
|
|
services.AddPersistenceDbContext(Configuration);
|
2024-11-27 17:59:37 +05:00
|
|
|
|
services.AddAuthorization();
|
2024-11-20 15:22:23 +05:00
|
|
|
|
services.AddJWTAuthentication(Configuration);
|
2024-11-14 15:17:43 +05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
app.UseSwagger();
|
|
|
|
|
app.UseSwaggerUI();
|
|
|
|
|
|
|
|
|
|
app.UseRouting();
|
|
|
|
|
|
2024-11-22 15:47:00 +05:00
|
|
|
|
if (env.IsDevelopment())
|
|
|
|
|
{
|
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-27 17:59:37 +05:00
|
|
|
|
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
|
2024-11-20 15:22:23 +05:00
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
app.UseAuthorization();
|
2024-11-14 15:17:43 +05:00
|
|
|
|
|
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
|
{
|
|
|
|
|
endpoints.MapControllers();
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-11-15 16:29:15 +05:00
|
|
|
|
|
|
|
|
|
public static void BeforeRunHandler(IHost host)
|
|
|
|
|
{
|
|
|
|
|
using var scope = host.Services.CreateScope();
|
|
|
|
|
var provider = scope.ServiceProvider;
|
|
|
|
|
|
|
|
|
|
var context = provider.GetRequiredService<PersistenceDbContext>();
|
|
|
|
|
context.Database.EnsureCreatedAndMigrated();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-11-14 15:17:43 +05:00
|
|
|
|
}
|