Skip to content

Enable support for seeds with multiple dependencies#10

Merged
neoscie merged 31 commits into
mainfrom
feature/multi-dependency
Jul 10, 2026
Merged

Enable support for seeds with multiple dependencies#10
neoscie merged 31 commits into
mainfrom
feature/multi-dependency

Conversation

@neoscie

@neoscie neoscie commented Jul 27, 2025

Copy link
Copy Markdown
Contributor
  • Replacing the tree-based dependency resolution with a robust, graph-based approach using Kahn's algorithm, enabling support for multi-dependencies and preventing circular dependencies.
  • Simplifying the seed dependency declaration by utilizing the DependsOnAttribute.
  • Adding a data seeding demo that simulates a Content Management System (CMS) seeding scenario.

neoscie added 30 commits October 3, 2024 16:56
…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.
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.
@neoscie
neoscie merged commit 32f593c into main Jul 10, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant