| | | 1 | | using Microsoft.EntityFrameworkCore; |
| | | 2 | | using TicTacToeApp.API.Data; |
| | | 3 | | using TicTacToeApp.API.Endpoints; |
| | | 4 | | using TicTacToeApp.API.Extensions; |
| | | 5 | | using TicTacToeApp.API.Interfaces; |
| | | 6 | | using TicTacToeApp.API.Repositories; |
| | | 7 | | using TicTacToeApp.API.Middleware; |
| | | 8 | | |
| | 0 | 9 | | var builder = WebApplication.CreateBuilder(args); |
| | | 10 | | |
| | 0 | 11 | | builder.Services |
| | 0 | 12 | | .AddSerializeServices() |
| | 0 | 13 | | .AddCors() |
| | 0 | 14 | | .AddSwaggerServices() |
| | 0 | 15 | | .AddScoped<IGameAsyncRepository, GameAsyncRepository>() |
| | 0 | 16 | | .AddDbContext<TicTacToeContext>(o => |
| | 0 | 17 | | o.UseNpgsql(builder.Configuration.GetConnectionString("PostgreSQL"))); |
| | | 18 | | |
| | 0 | 19 | | var app = builder.Build(); |
| | | 20 | | |
| | 0 | 21 | | if (app.Environment.IsProduction()) |
| | | 22 | | { |
| | 0 | 23 | | using var scope = app.Services.CreateScope(); |
| | 0 | 24 | | var dbContext = scope.ServiceProvider.GetRequiredService<TicTacToeContext>(); |
| | 0 | 25 | | dbContext.Database.EnsureDeleted(); |
| | 0 | 26 | | dbContext.Database.Migrate(); |
| | | 27 | | } |
| | | 28 | | |
| | 0 | 29 | | app.UseMiddleware<ExceptionHandlerMiddleware>(); |
| | 0 | 30 | | app.UseCors(o => o.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()); |
| | 0 | 31 | | app.UseSwaggerMiddleware(); |
| | 0 | 32 | | app.UseGameEndpoints(); |
| | | 33 | | |
| | 0 | 34 | | app.Run(); |