Closed rustam-ashurov-mcx closed 3 months ago
@rustam-ashurov-mcx Hello, Rustam!
Seems like you doing something like this https://python-dependency-injector.ets-labs.org/examples/application-multiple-containers.html.
I'm personally don't like of idea of multiple containers and can't give advices for such use cases. But that-depends
can be used with multiple containers like this https://that-depends.readthedocs.io/introduction/multiple-containers.html
Hey mates, On the main page it's said that this lib is good to switch from dependency-injector so I'm hyped already. But can this library help with wiring FastAPI routers which are defined in a library and should be used eventually in a customer application code?
To elaborate a bit more about my particular example (which fails with other DI libraries):
I want to make a library with some REST API routers for FastAPI application and with some DI bindings to pre-configured so my routers will receive my services:
Here is the LoggignContainer where I have logging-related dependencies:
And here is a main BaseContainer where I aggregated all smaller containers from my library, it then can be used in the client code to register (for me) and access (for client) my services if needed:
Here is my library router which should automate some work, very simple one and which uses services registred in IoC Contaier from my lib, specifically my logger:
In a client code some steps should be done, firstly a client Container to be defined, it has it's own application-related dependencies + inherits from my BaseContainer:
Now client code need to register the library router (typical registration via FastAPI methods) + wire the router :
My expectations are Logger from my library will be injected in my router but the results is: "AttributeError: 'Provide' object has no attribute logger"
I tried many combinations and changed code many ways but unless I directly use AppContainer in my library code (what is impossible to expect beyond local examples and testing since I can not know what is App level container in advance) wiring doesn't work
So now I started to check you examples and in the FastAPI example I see such lines of code:
Where ioc.IOCContainer.decks_repo is a reference to the container in the application code and I decided to ask in advance.
Is it possible in your lib to:
Thank you 🙂