-
Notifications
You must be signed in to change notification settings - Fork 8
Upgrade to .NET 10.0 and update NuGet packages #823
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
69f906d
5c0a65a
a367dc9
0924c9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -16,22 +16,33 @@ protected override void ConfigureWebHost(IWebHostBuilder builder) | |||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| builder.ConfigureServices(services => | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| ServiceDescriptor? descriptor = services.SingleOrDefault( | ||||||||||||||||||||||||||||||
| d => d.ServiceType == | ||||||||||||||||||||||||||||||
| typeof(DbContextOptions<EssentialCSharpWebContext>)); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Remove the existing DbContext and related services | ||||||||||||||||||||||||||||||
| var descriptorType = typeof(DbContextOptions<EssentialCSharpWebContext>); | ||||||||||||||||||||||||||||||
| var descriptor = services.SingleOrDefault(d => d.ServiceType == descriptorType); | ||||||||||||||||||||||||||||||
| if (descriptor != null) | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| services.Remove(descriptor); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Remove all DbContextOptions related services to avoid EF Core 10 multiple provider error | ||||||||||||||||||||||||||||||
| var allDbContextOptions = services.Where(d => | ||||||||||||||||||||||||||||||
| d.ServiceType.IsGenericType && | ||||||||||||||||||||||||||||||
| d.ServiceType.Name.Contains("DbContextOptions")).ToList(); | ||||||||||||||||||||||||||||||
| foreach (var desc in allDbContextOptions) | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| services.Remove(desc); | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
Comment on lines
+28
to
+34
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| _Connection = new SqliteConnection(SqlConnectionString); | ||||||||||||||||||||||||||||||
| _Connection.Open(); | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| // Add SQLite DbContext without using the global service provider | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| services.AddDbContext<EssentialCSharpWebContext>(options => | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| options.UseSqlite(_Connection); | ||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||
| // Disable service provider caching to avoid shared state in EF Core 10 | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| // Disable service provider caching to avoid shared state in EF Core 10 | |
| // EF Core 10 change: DbContextOptions now participate more aggressively in internal | |
| // service provider caching so that model- and provider-specific services can be reused | |
| // across contexts. In this test setup we create many WebApplicationFactory instances that | |
| // all share the same in-memory SQLite connection. If EF Core caches the internal service | |
| // provider globally, state for one test run (e.g., model metadata, conventions, and | |
| // provider services) can be reused by another, causing "multiple providers" errors and | |
| // flaky tests due to unexpected shared state between factories. | |
| // | |
| // Disabling service provider caching forces EF Core to build a fresh internal service | |
| // provider for each DbContextOptions instance, isolating tests at the cost of a small | |
| // per-context startup overhead. This trade-off is acceptable for integration tests, but | |
| // should generally be avoided in production code where the additional allocations and | |
| // startup cost could impact performance. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "sdk": { | ||
| "version": "9.0.101", | ||
| "version": "10.0.100", | ||
| "rollForward": "latestMinor" | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment on line 19 mentions "Remove the existing DbContext and related services" but the code only removes a single service descriptor (lines 20-25). The broader removal happens in the subsequent block (lines 27-34). Consider moving this comment to line 27 or updating it to clarify that this first block only removes the primary DbContext service.