What problem does it solve?
This Skill helps teams organize and reuse dependency injection registrations in ASP.NET Core applications by encapsulating related registrations inside small composable extension methods, keeping Program.cs clean and tests easily configurable.
Core Features & Use Cases
- Encapsulated Add*Methods: Create extension methods like AddUserServices(), AddOrderServices(), and AddEmailServices() to group related registrations and improve readability.
- Test-time configurability: Allow tests to override specific services while reusing production registrations, improving maintainability and resilience.
- Lifetime and configuration cohesion: Centralize configuration and lifetimes in one place, reducing duplication and ensuring consistent behavior across environments.
- Use Case: In a large web app, split registrations into modular areas (Users, Orders, Payments) and compose them in the top-level AppServiceCollectionExtensions.
Quick Start
Create extension methods on IServiceCollection (e.g., AddUserServices, AddOrderServices) that register related services and return IServiceCollection. Then, in your Program.cs, call services.AddUserServices().AddOrderServices() as part of app startup.