Skip to content

How to create multiple scoped container? #912

@sherlock1982

Description

@sherlock1982

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

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