I read Dependency Injection Principles, Practices, and Patterns and I try to figured out what actually is the difference between Composition Root and Composer.
In the book their definitions are:
Composition Root is a single, logical location in an application where modules are composed together.
Composer is a unifying term to refer to any object or method that composes Dependencies. Itβs an important part of the Composition Root. The Composer is often a DI Container, but it can also be any method that constructs object graphs manually (using Pure DI).
Is Composition Root more like the name of the place/location where we should create our application graph and Composer is that thing which actually does it? Or it is something else?
If you use a DI Container, the Composition Root should be the only place where you use the DI Container.
What else you possible could have in Composition Root ? Isn't it only A DI Container?
public class CompositionRoot
{
public static IContainer Compose()
{
var builder = new ContainerBuilder();
builder.RegisterType<Calculator>().As<ICalculator>().SingleInstance();
return builder.Build();
}
}
Regards