Skip to content

Q: Is it possible to use DependenciesContainer when defining a provider_type? #384

Open
@ms-lolo

Description

@ms-lolo

I'm trying to define a container that only provides instances that extend Foo, however, some of these instances depend on things provided by other containers. Is this possible and what would the best approach be? Here's a sample mostly taken from multiple parts of your docs:

class MainContainer(DeclarativeContainer):
    some_client = Singleton(SomeClient)

class SpecificProvider(Singleton):
    provided_type = SpecificThing

class SpecificThingsContainer(DeclarativeContainer):
    provider_type = SpecificProvider

    # this causes an error
    # if possible, I would actually prefer to hide this from the public interface of my "things" container
    main_container = DependenciesContainer()

    # how do I define this dependency on SomeClient?
    one_thing = SpecificProvider(SpecificThing, client=main_container.some_client)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions