Skip to content

Commit 6e252af

Browse files
nanotaboadaclaude
andcommitted
refactor(config): rename AddDbContextPool to AddPlayerDbContext; add retry (#249)
- Rename AddDbContextPool -> AddPlayerDbContext to follow the Add{Feature} naming convention and avoid shadowing EF Core's own AddDbContextPool; update call site in Program.cs accordingly - Add EnableRetryOnFailure() to the Npgsql path so MigrateAsync() and subsequent queries survive transient connection blips at startup Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent f937601 commit 6e252af

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

src/Dotnet.Samples.AspNetCore.WebApi/Extensions/ServiceCollectionExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ namespace Dotnet.Samples.AspNetCore.WebApi.Extensions;
2222
public static partial class ServiceCollectionExtensions
2323
{
2424
/// <summary>
25-
/// Adds DbContextPool for PlayerDbContext, selecting the database provider based on the
25+
/// Adds PlayerDbContext, selecting the database provider based on the
2626
/// <c>DATABASE_PROVIDER</c> environment variable (<c>sqlite</c> by default, <c>postgres</c>
2727
/// to opt in to PostgreSQL).
2828
/// </summary>
2929
/// <param name="services">The IServiceCollection instance.</param>
3030
/// <param name="environment">The web host environment.</param>
3131
/// <returns>The IServiceCollection for method chaining.</returns>
32-
public static IServiceCollection AddDbContextPool(
32+
public static IServiceCollection AddPlayerDbContext(
3333
this IServiceCollection services,
3434
IWebHostEnvironment environment
3535
)
@@ -48,7 +48,7 @@ IWebHostEnvironment environment
4848
throw new InvalidOperationException(
4949
"DATABASE_URL is required when DATABASE_PROVIDER=postgres."
5050
);
51-
options.UseNpgsql(connectionString);
51+
options.UseNpgsql(connectionString, npgsql => npgsql.EnableRetryOnFailure());
5252
// Hand-crafted designer files cannot replicate Npgsql-injected runtime
5353
// annotations (Relational:MaxIdentifierLength, UseIdentityByDefaultColumn),
5454
// causing a false-positive PendingModelChangesWarning. Suppressed here;

src/Dotnet.Samples.AspNetCore.WebApi/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
/* Data --------------------------------------------------------------------- */
5656

57-
builder.Services.AddDbContextPool(builder.Environment);
57+
builder.Services.AddPlayerDbContext(builder.Environment);
5858

5959
var app = builder.Build();
6060

0 commit comments

Comments
 (0)