Used service provider, inside extension method, to create simple seed data. When requested EF Core's DbContext from dependency injection via GetRequiredService application freezes, have run it both in Rider and Visaul Studio, and had the same issue on both
public static async ValueTask InitializeSeedAsync(this IServiceProvider serviceProvider)
{
var identityDbContext = serviceProvider.GetRequiredService<IdentityDbContext>();
if (!await identityDbContext.Users.AnyAsync())
await identityDbContext.SeedUsersAsync();
}
from the code snippet above, I'm referring to this call - serviceProvider.GetRequiredService<IdentityDbContext>();, after spending some time doing profiling ( sorry if I've taken wrong snapshots, I'm not skilled in this ), I observed these things
many worker threads being used just for that call too
call stack is looped around GetRequiredService
Expected Behavior
dependency resolved after the call
if not possible exception with details
Steps To Reproduce
I have been working in some demonstration projects for training purposes so the code for this project is fully open at link
Branch - bug/di-issue
To run it
do migrations for your local database
run the project
Exceptions (if any)
It shouldn't have any exceptions if migrations are done correctly
Is there an existing issue for this?
Describe the bug
DI functionality causing the bug
Used service provider, inside extension method, to create simple seed data. When requested EF Core's
DbContext
from dependency injection viaGetRequiredService
application freezes, have run it both in Rider and Visaul Studio, and had the same issue on bothfrom the code snippet above, I'm referring to this call -
serviceProvider.GetRequiredService<IdentityDbContext>();
, after spending some time doing profiling ( sorry if I've taken wrong snapshots, I'm not skilled in this ), I observed these thingsGetRequiredService
Expected Behavior
Steps To Reproduce
I have been working in some demonstration projects for training purposes so the code for this project is fully open at link
Branch - bug/di-issue
To run it
Exceptions (if any)
It shouldn't have any exceptions if migrations are done correctly
.NET Version
8.0
Anything else?
Framework
Ide
Rider
Visual Studio
Dotnet info result
.NET SDK: Version: 8.0.100 Commit: 57efcf1350 Workload version: 8.0.100-manifests.6c33ef20
Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.100\
.NET workloads installed: Workload version: 8.0.100-manifests.6c33ef20 There are no installed workloads to display.
Host: Version: 8.0.0 Architecture: x64 Commit: 5535e31a71
.NET SDKs installed: 3.1.426 [C:\Program Files\dotnet\sdk] 6.0.413 [C:\Program Files\dotnet\sdk] 7.0.305 [C:\Program Files\dotnet\sdk] 7.0.404 [C:\Program Files\dotnet\sdk] 8.0.100 [C:\Program Files\dotnet\sdk]
.NET runtimes installed: Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables: Not set
global.json file: Not found
Profile snapshot files https://drive.google.com/file/d/150nIp2QcqDhqgHO1fnvrJqtwWdmzzEXK/view?usp=sharing https://drive.google.com/file/d/152e3fC4vvTxqbybWHYpNs3-coFbW_ejb/view?usp=sharing