On Saturday, 1 November 2014 at 18:54:04 UTC, Gary Willoughby
wrote:
It's the fundamental way dependency injection containers are
used. Instead of having complex dependencies on other resources
you can just rely on the container to serve resources as needed.
For example if you have a class which needs the Greeter service
you will either have to embed that service using composition or
pass it into the class via a constructor or setter. A container
is a single place where this and many other services can be
retrieved. This also means that anything wanting to use the
container is also dependent on it but this is sometimes less
complicated than dealing with all the other dependencies
individually. Also some dependencies have complicated rules for
creating them which some dependency injection containers deal
with, again removing this code from where the resource is
actually being used.
But then you have to pass the container around? Or you make it a
singleton?