From d804e9236358d32f68859c2628493267e22f0895 Mon Sep 17 00:00:00 2001 From: Chunyi Date: Tue, 30 Sep 2025 13:10:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=B3=87=E6=96=99=E5=BA=AB?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E6=96=87=E9=85=8D=E7=BD=AE=E8=88=87=E6=87=89?= =?UTF-8?q?=E7=94=A8=E7=A8=8B=E5=BC=8F=E5=BB=BA=E7=AB=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 在 `Program.cs` 中,將 `AddDbContext` 更改為 `AddDbContextPool`,並新增 MySQL 重試機制,最多重試 5 次,每次重試間隔 30 秒。此外,新增應用程式的建立步驟,並保留 Swagger 的設定。 --- XisongSpaceBooking_BackEnd/Program.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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(); -// tm Entity Framework -builder.Services.AddDbContext(options => +// tm Entity Framework Psu +builder.Services.AddDbContextPool(options => { var connectionString = builder.Configuration.GetConnectionString("DefaultConnection"); options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString), mySqlOptions => { + // su]w mySqlOptions.EnableRetryOnFailure( maxRetryCount: 5, maxRetryDelay: TimeSpan.FromSeconds(30), @@ -27,6 +28,7 @@ builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Qaw/Xisong Space Booking API", Version = "v1" }); }); + var app = builder.Build(); // Configure the HTTP request pipeline.