python-dependency-injector
python-dependency-injector copied to clipboard
Dependency injection framework for Python
Is there a tool that automativally generates (mainly command line) intefaces from Configurations. I am imaginaning something in the spirit of [python-fire](https://github.com/google/python-fire), that uses Configurations instead of (or in addition...
https://python-dependency-injector.ets-labs.org/examples/application-multiple-containers.html - I have setup identical to this example. `user_service: UserService = Provide[Application.services.user]` - I get typing hints for Application (i.e. editor suggest `services` as autocomplete), bet not for services...
Im witnessing the `init` method run several times on my `resources.Resource` class. Heres my setup: `dependency_containers.py` ``` class MyResource(resources.Resource): def init(self): print("initialized") return MyResourceClass() ... ... class SomeOtherResource(containers.DeclarativeContainer): my_resource =...
Consider this example: ```python class TestClass: @inject def test(self, resource=Closing[Provide["resource"]]): assert resource == "resource" print("test_class") @inject def global_test( resource=Closing[Provide["resource"]], test_class1: TestClass = Provide["test_class"], test_class2: TestClass = Provide["test_class"], ): assert resource...
When trying to create a container in a pytest fixture with pytest-asyncio, I had the effect that pytest ran forever with no error message showing up. Here is a simplified...
This works: ```python class Foo: def __init__(self, bar): self.bar = bar class SubContainer(containers.DeclarativeContainer): wiring_config = containers.WiringConfiguration( modules=[__name__], packages=[] ) bar = providers.Dependency(instance_of=str) foo = providers.Factory(Foo, bar=bar) class MainContainer(containers.DeclarativeContainer): wiring_config =...
Upon upgrading from 4.37.0 to 4.41.0 we now have failures throughout our test cases whenever we attempt to explicitly pass constructor arguments to a class wired up with dependency-injector for...
Let's say I have this yaml configuration: ``` selected: option1 option1: param1:... param2:.... option2: param1:... param2:... ``` I want to be able to do something like this: ``` class Container(containers.DeclarativeContainer):...
The following code ```python self.deployments_service = providers.Factory( DeploymentService, base_url=self.config.deployments.base_url(), timeout=self.config.deployments.timeout.as_(tuple), transport=httpx.AsyncHTTPTransport( retries=self.config.deployments.retries.as_int() ), ) ``` requires a "double function call" on the `as_int` type cast method: ```python self.deployments_service = providers.Factory(...