dependency_injector.containers

Dependency injector containers.

Powered by Cython.

class dependency_injector.containers.DeclarativeContainer

Declarative inversion of control container.

class Services(DeclarativeContainer):
    auth = providers.Factory(AuthService)
    users = providers.Factory(UsersService,
                              auth_service=auth)
__new__

Constructor.

Returns:Dynamic container with copy of all providers.
Return type:DynamicContainer
__weakref__

list of weak references to the object (if defined)

instance_type

alias of DynamicContainer

classmethod override()

Override current container by overriding container.

Parameters:overriding (DeclarativeContainer) – Overriding container.
Raise:dependency_injector.errors.Error if trying to override container by itself or its subclasses
Return type:None
provider_type

alias of Provider

classmethod reset_last_overriding()

Reset last overriding provider for each container providers.

Return type:None
classmethod reset_override()

Reset all overridings for each container providers.

Return type:None
class dependency_injector.containers.DeclarativeContainerMetaClass

Declarative inversion of control container meta class.

__delattr__()

Delete class attribute.

If value of attribute is provider, it will be deleted from providers dictionary.

Parameters:name (str) – Attribute’s name
Return type:None
__new__

Declarative container class factory.

__setattr__()

Set class attribute.

If value of attribute is provider, it will be added into providers dictionary.

Parameters:
  • name (str) – Attribute’s name
  • value (object) – Attribute’s value
Return type:

None

class dependency_injector.containers.DynamicContainer

Dynamic inversion of control container.

services = DynamicContainer()
services.auth = providers.Factory(AuthService)
services.users = providers.Factory(UsersService,
                                   auth_service=services.auth)
providers

Read-only dictionary of all providers.

Type:dict[str, dependency_injector.providers.Provider]
overridden

Tuple of overriding containers.

Type:tuple[DynamicContainer]
provider_type

Type of providers that could be placed in container.

Type:type
__delattr__()

Delete instance attribute.

If value of attribute is provider, it will be deleted from providers dictionary.

Parameters:name (str) – Attribute’s name
Return type:None
__init__()

Initializer.

Return type:None
__setattr__()

Set instance attribute.

If value of attribute is provider, it will be added into providers dictionary.

Parameters:
  • name (str) – Attribute’s name
  • value (object) – Attribute’s value
Return type:

None

__weakref__

list of weak references to the object (if defined)

override()

Override current container by overriding container.

Parameters:overriding (DynamicContainer) – Overriding container.
Raise:dependency_injector.errors.Error if trying to override container by itself
Return type:None
reset_last_overriding()

Reset last overriding provider for each container providers.

Return type:None
reset_override()

Reset all overridings for each container providers.

Return type:None
dependency_injector.containers.copy()

DeclarativeContainer copying decorator.

This decorator copy all providers from provided container to decorated one. If one of the decorated container providers matches to source container providers by name, it would be replaced by reference.

Parameters:container (DeclarativeContainer) – Container that should be copied by decorated container.
Returns:Declarative container’s copying decorator.
Return type:callable(DeclarativeContainer)
dependency_injector.containers.is_container()

Check if instance is container instance.

Parameters:instance (object) – Instance to be checked.
Return type:bool
dependency_injector.containers.override()

DeclarativeContainer overriding decorator.

Parameters:container (DeclarativeContainer) – Container that should be overridden by decorated container.
Returns:Declarative container’s overriding decorator.
Return type:callable(DeclarativeContainer)