diff --git a/XisongSpaceBooking_BackEnd/Program.cs b/XisongSpaceBooking_BackEnd/Program.cs index 1830afa..93650b9 100644 --- a/XisongSpaceBooking_BackEnd/Program.cs +++ b/XisongSpaceBooking_BackEnd/Program.cs @@ -7,13 +7,14 @@ var builder = WebApplication.CreateBuilder(args); // Add services to the container. builder.Services.AddControllers(); -// 配置 Entity Framework -builder.Services.AddDbContext(options => +// 配置 Entity Framework 與連線池 +builder.Services.AddDbContextPool(options => { var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString), mySqlOptions => { + // 連線池相關設定 mySqlOptions.EnableRetryOnFailure( maxRetryCount: 5, maxRetryDelay: TimeSpan.FromSeconds(30), @@ -27,6 +28,7 @@ builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "西松高中場地預約/Xisong Space Booking API", Version = "v1" }); }); + var app = builder.Build(); // Configure the HTTP request pipeline.