更新資料庫上下文配置與應用程式建立
在 `Program.cs` 中,將 `AddDbContext<SpaceBookingDbContext>` 更改為 `AddDbContextPool<SpaceBookingDbContext>`,並新增 MySQL 重試機制,最多重試 5 次,每次重試間隔 30 秒。此外,新增應用程式的建立步驟,並保留 Swagger 的設定。
This commit is contained in:
parent
9027f7d93d
commit
d804e92363
@ -7,13 +7,14 @@ var builder = WebApplication.CreateBuilder(args);
|
|||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
|
|
||||||
// °t¸m Entity Framework
|
// °t¸m Entity Framework »P³s½u¦À
|
||||||
builder.Services.AddDbContext<SpaceBookingDbContext>(options =>
|
builder.Services.AddDbContextPool<SpaceBookingDbContext>(options =>
|
||||||
{
|
{
|
||||||
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||||
options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString),
|
options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString),
|
||||||
mySqlOptions =>
|
mySqlOptions =>
|
||||||
{
|
{
|
||||||
|
// ³s½u¦À¬ÛÃö³]©w
|
||||||
mySqlOptions.EnableRetryOnFailure(
|
mySqlOptions.EnableRetryOnFailure(
|
||||||
maxRetryCount: 5,
|
maxRetryCount: 5,
|
||||||
maxRetryDelay: TimeSpan.FromSeconds(30),
|
maxRetryDelay: TimeSpan.FromSeconds(30),
|
||||||
@ -27,6 +28,7 @@ builder.Services.AddSwaggerGen(c =>
|
|||||||
{
|
{
|
||||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "¦èªQ°ª¤¤³õ¦a¹w¬ù/Xisong Space Booking API", Version = "v1" });
|
c.SwaggerDoc("v1", new OpenApiInfo { Title = "¦èªQ°ª¤¤³õ¦a¹w¬ù/Xisong Space Booking API", Version = "v1" });
|
||||||
});
|
});
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user