Structure of Dependency Injector

Current section describes Dependency Injector main entities and their interaction between each other.


There are 2 main entities: providers & containers.


Providers are strategies of accessing objects. For example, dependency_injector.providers.Factory creates new instance of provided class every time it is called. dependency_injector.providers.Singleton creates provided instance once and returns it on every next call. Base class is - dependency_injector.providers.Provider.

Providers could be:

  • Injected into each other.
  • Overridden by each other.
  • Extended.


Containers are collections of providers. They are used for grouping of providers by some principles. Base class is - dependency_injector.containers.DeclarativeContainer.

Containers could be:

  • Overridden by each other.
  • Copied from each other.
  • Extended.