Remove Aspire EF Core integration, use standard EF Core 8 with manual configuration

Co-authored-by: collinbarrett <6483057+collinbarrett@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2025-11-13 03:08:16 +00:00 committed by Collin Barrett
parent 7fb40b2cdb
commit 99428cf156
2 changed files with 20 additions and 13 deletions

View file

@ -1,6 +1,7 @@
using FilterLists.Directory.Infrastructure.Persistence.Queries;
using FilterLists.Directory.Infrastructure.Persistence.Queries.Context;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
@ -12,17 +13,25 @@ public static class ConfigurationExtensions
public static void AddInfrastructure(this IHostApplicationBuilder builder)
{
// TODO: use different connection strings for migrations and queries (https://stackoverflow.com/q/78564037/2343739)
builder.AddSqlServerDbContext<QueryDbContext>("directorydb",
_ => { },
o => o.UseSqlServer(so =>
// retry on Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - Undefined error: 0)
so.EnableRetryOnFailure([0])
.MigrationsAssembly(MigrationsAssembly))
.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
.EnableSensitiveDataLogging(string.Equals(
Environment.GetEnvironmentVariable("DOTNET_RUNNING_EF_CORE_TOOLS"), "true",
StringComparison.OrdinalIgnoreCase)));
// Get connection string from configuration
var connectionString = builder.Configuration.GetConnectionString("directorydb")
?? throw new InvalidOperationException("Connection string 'directorydb' not found.");
// Register DbContext with standard EF Core configuration
builder.Services.AddDbContext<QueryDbContext>(options =>
{
options.UseSqlServer(connectionString, sqlServerOptions =>
{
// retry on Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: TCP Provider, error: 0 - Undefined error: 0)
sqlServerOptions.EnableRetryOnFailure(errorNumbersToAdd: [0]);
sqlServerOptions.MigrationsAssembly(MigrationsAssembly);
});
options.UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking);
options.EnableSensitiveDataLogging(string.Equals(
Environment.GetEnvironmentVariable("DOTNET_RUNNING_EF_CORE_TOOLS"), "true",
StringComparison.OrdinalIgnoreCase));
});
builder.Services.AddHostedService<MigrationService>();
}

View file

@ -5,9 +5,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" Version="13.0.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.22"/>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.22"/>
</ItemGroup>
</Project>