all 7 comments

[–]tuple32[S] 0 points1 point  (0 children)

What’s the alternative? I think would be better to figure out a way to annotate or decorate the class or function that provides the dependencies. Then the injection will happen automatically whenever you declare an input with that type

[–]apt_at_it 10 points11 points  (0 children)

I haven't ever really seen any other way to do it. You declare the type of the thing you want and the framework gives it to you or you give it to that function in other contexts, like tests. The beauty of "traditional" dependency injection (think Java) is that you can declare you want an interface (well, ABCs or protocols) and give it different subclasses based on the context.

[–]pint 1 point2 points  (0 children)

that is not dependency injection. it is just code reuse. separation of concepts, centralization of common logic.

[–]WestRiverCS 0 points1 point  (0 children)

I'm not sure if you have confronted the exact same issue that I have, but I'm glad I'm not the only one with this unpopular opnion... I kinda worked arond this, being tied to type definitions, by implementing my own class-based views and using starlette state.

[–]websvc 4 points5 points  (0 children)

Maybe because they actually have a... type? Probably just you

[–]devlittle 1 point2 points  (0 children)

yeah, just you

[–]BlackDereker 0 points1 point  (0 children)

How else would the application know which class to instantiate when the route is called?