Skip to content

Dependencies are not injected when creating injections into a module using "providers.DependenciesContainer" #551

Open
@satodaiki

Description

@satodaiki

hello.

The following code tries to use SubContainer to perform dependency injection into a Service, but this code cannot be executed with the exception "exception: no description".

from dependency_injector import containers, providers
from dependency_injector.wiring import Provide


class Service:
    ...


class Container(containers.DeclarativeContainer):

    sub_container = providers.DependenciesContainer()

class SubContainer(containers.DeclarativeContainer):
    
    service = providers.Factory(Service)

service: Service = Provide[Container.sub_container.service]


if __name__ == "__main__":
    container = Container()
    container.wire(modules=[__name__])

    assert isinstance(service, Service)

How can I perform dependency injection into a SubContainer?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions