Enable support for seeds with multiple dependencies#10
Merged
Conversation
And added unit tests
…ection using Kahn's algorithm in DependencyResolver
Ensures that seeds can properly resolve scoped dependencies by creating a scope and resolving the seeds within that scope.
Refactors the code to directly cast the resolved service to ISeed within the 'if' condition.
- Fix ObjectDisposedException when seeds use scoped dependencies like UserManager - Use temporary scope for dependency analysis to handle scoped services - Resolve fresh seed instances within execution scope instead of caching - Register seeds as both concrete types and interfaces for proper DI resolution - Add comprehensive tests for scope disposal scenarios and scoped service dependencies Resolves issue where seeds with scoped dependencies (e.g., UserManager<T>) would throw ObjectDisposedException because they were resolved from a disposed scope during dependency analysis phase and then executed later. Changes: - Seeding.UseServiceProvider: Use temporary scope for seed resolution during analysis - Seeder.SeedAsync: Create fresh scope and resolve fresh seed instances during execution - ServiceCollectionExtensions: Register seeds with .AsSelf() for concrete type resolution - Add ScopeDisposalTests to verify fix and prevent regression - Add FakeScopedServiceWithDependency to simulate UserManager-like scenarios - Add ScopedServiceWithDependencySeed test seed for integration testing Breaking changes: None - fully backward compatible
- Enhanced scoped service support documentation - Added abstract Seed class documentation - Improved scoped service lifecycle management details - Added comprehensive examples for enterprise scenarios - Fixed markdown formatting issues
Migrates projects and build pipelines to target .NET 8. This includes updating `TargetFrameworks` in several `csproj` files and adjusting the `DOTNET_VERSION` in GitHub Actions workflows to use .NET 8. Package references for `Microsoft.Extensions` were also updated to their latest .NET 8 compatible versions.
This was referenced Jul 29, 2025
Prevents accidental duplicate seed registrations by introducing a check that throws an `InvalidOperationException` if the same `ISeed` type is registered more than once. This enhances robustness and provides clearer error messages for common setup issues when configuring data seeding.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DependsOnAttribute.