mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
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:
parent
7fb40b2cdb
commit
99428cf156
2 changed files with 20 additions and 13 deletions
|
|
@ -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>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
Loading…
Reference in a new issue