From what I noticed, they do pretty much the same thing, provide services in form of IoC/DI. However, IAmbientServices
has a member of type ICompositionContext
. I don't really get the difference between the two of them and why are they aggregated this way?
The concise answer is: the ambient services
contain services registered before the IoC/DI/composition container is built, while the composition context
is the root container for the IoC/DI, and itself is a service registered into the ambient services
.
As a side note, all the services registered in the ambient services
are later registered automatically also in the DI container, including IAmbientServices
, so they are available for composition, too.
Examples for ambient services:
As a general rule of thumb, prefer using services registered in the DI container, you will need very rarely ambient services.