What is a Composition Root?
Updated Apr 28, 2026
Short answer
The Composition Root is the single, centralized location in an application where modules are wired together and dependencies are registered.
Deep explanation
It should be as close to the application's entry point as possible (e.g., Program.cs, main()). Only the Composition Root should interact with the DI container. The rest of the application should remain entirely ignorant of the container.
Real-world example
The Startup.cs file in an ASP.NET application or the AppModule in an Angular application.
Common mistakes
- Sprinkling container registrations or configuration files across multiple business logic layers.
Follow-up questions
- Why shouldn't business logic libraries have their own Composition Roots?