modern-python / that-depends

DI-framework, inspired by python-dependency-injector, but without wiring. Python 3.12 is supported
https://that-depends.readthedocs.io/
MIT License
133 stars 10 forks source link

How use multiple containers #24

Closed yurihartmann closed 3 months ago

yurihartmann commented 3 months ago

I am using dependency-injector lib and i want migrate, but how I migrate using multiple containers:

Docs: https://python-dependency-injector.ets-labs.org/examples/application-multiple-containers.html

In dependency-injector, I use that expression

class AgentsContainer(containers.DeclarativeContainer):
    drivers: DriversContainer = providers.DependenciesContainer()

And in AppContainer:

    agents_container: AgentsContainer = providers.Container(AgentsContainer, drivers=drivers)

How I do that in that-depends lib?

lesnik512 commented 3 months ago

I will think of this use case. Looks like its not very hard to implement.

lesnik512 commented 3 months ago

@yurihartmann Can you please describe what are you to trying to achieve with multiple containers? Just to split big container into smaller ones?

yurihartmann commented 3 months ago

Yes, im big projects, split in little container for each service, is more organized and simple to search what you want

jonathangreen commented 3 months ago

👍🏻 to this request. I'm looking at this project as a possible migration path from python-dependency-injector, and my projects also use multiple containers.

I think this example from that projects docs gives a good idea how multi-container functionality is used: https://python-dependency-injector.ets-labs.org/examples/application-multiple-containers.html

lesnik512 commented 3 months ago

Multiple containers can be used as described here https://that-depends.readthedocs.io/introduction/multiple-containers.html