You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello! I started playing around with dishka, looking for some alternative to dependency-injector, and I really liked it conteptually, especially scopes and type-based injections.
Unfortunetly, when trying to introduce it to django project, I found out one missing feature from dependency-injector, i.e. in place providers overriding. I managed to succesfully integrate container to inject dependencies into django views, but things get tricky when it comes to tests. It's very hard, if not impossible, to setup django tests with pytest in simillar manner as with more modern frameworks, i.e. by creating whole new application object that could be passed around in pytest fixtures, with it's own tests container attached.
I found other issue about container overriding: #151 , but it mentions cloning container with different providers, which would not help in my case. I guess only overriding in context manager (independent of scopes), or with teardown method (I mean, overriding in place, not cloning) would help in my case. Like in dependency-injectorhttps://python-dependency-injector.ets-labs.org/providers/overriding.html
Apart of solving problems with Django specifically, it would also make possible to use pattern in pytest that I find very helpful, i.e. incrementally overriding providers in different tests scopes, taking adventage of how pytest look for fixtures: https://docs.pytest.org/en/6.2.x/fixture.html#fixture-availability
So for example, I would define most general overrides on container fixture in root conftest.py, and then add more specific overrides in more narrow scopes, using pattern:
We have plans for this in one of future releases (#231), but it is not actually required for you.
The container is rebuilt from a list of providers. To build another container you can take the same list.. and add more providers to it. The latest factories override previous ones.
Hello! I started playing around with
dishka
, looking for some alternative todependency-injector
, and I really liked it conteptually, especially scopes and type-based injections.Unfortunetly, when trying to introduce it to django project, I found out one missing feature from
dependency-injector
, i.e. in place providers overriding. I managed to succesfully integrate container to inject dependencies into django views, but things get tricky when it comes to tests. It's very hard, if not impossible, to setup django tests withpytest
in simillar manner as with more modern frameworks, i.e. by creating whole new application object that could be passed around in pytest fixtures, with it's own tests container attached.I found other issue about container overriding: #151 , but it mentions cloning container with different providers, which would not help in my case. I guess only overriding in context manager (independent of scopes), or with teardown method (I mean, overriding in place, not cloning) would help in my case. Like in
dependency-injector
https://python-dependency-injector.ets-labs.org/providers/overriding.htmlApart of solving problems with Django specifically, it would also make possible to use pattern in pytest that I find very helpful, i.e. incrementally overriding providers in different tests scopes, taking adventage of how pytest look for fixtures:
https://docs.pytest.org/en/6.2.x/fixture.html#fixture-availability
So for example, I would define most general overrides on container fixture in root
conftest.py
, and then add more specific overrides in more narrow scopes, using pattern:Is it possible/feasible to implement that with your design?
The text was updated successfully, but these errors were encountered: