ets-labs/python-dependency-injector

How to create multiple scoped container?

Opened this issue · 0 comments

I have the following container which describes some User. It has both factories and singletons specific for this user.
It depends on a ClientSession object which can be injected from some other Root container:

class UserContainer(containers.DeclarativeContainer):
    client_session = providers.Dependency(instance_of=ClientSession)

    some_service = providers.Singleton(
        SomeService,
        client_session=client_session,
    )

Currently I simply override it when creating UserContainer:

    user_container = UserContainer(
        client_session=providers.Object(client_session),
    )

Is there a way I can provide a Root container instance itself to the UserContaner instance instead of providing the service itself? Note I can't mix them as singletons in UserContainer are scoped