Replies: 1 comment 1 reply
-
|
That would be better to have more details about the type of application you develop and its structure, but I'll try to explain some general logic. Though, you are not using a framework you might have a separation between normal functions and event handlers. I mean, there is some code that handles interaction with actor (user, queue, requests). This code triggers discovers that new action is requested (found input, event, message, whatever) and calls some handler. At a scope boundary (within event handler or within handler caller) we access a container, enter new scope (usually it is Request) and request your objects. These objects are created by container, they have dependencies and call other functions. Normally you do not access container here. You just use provided objects and call normal functions. And you do not access container anything from normal functions or classes, only from "event handlers". So, what am I saying here? You still have a "framework" layer, thought it is not a real framework, just some special part of code. You do not normally use container for framework configuration, but you use it to configure objects called from it. What can be different here? Ok, your main logic can still trigger an event which should be processed by accessing a container. It is an open question whether you call it directly or using queues. Anyway, you call here the same "framework" layer again. And the entrypoint to that layer is still injected into business logic using DI. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm evaluating whether dishka or IoC-containers in general can help simplifying my current approach that relies mostly on constructor and (especially) parameter injection. Note I am not using any particular framework (at least any of these listed under dishka integrations), just plain Python with asyncio.
In summary:
Now I have wrapped these dependencies into a
Provider, created aContainerwithmake_async_containerand trying to figure out how to pass it to the functions that need to access it:container, effectively making it a dependency itself. This would be an improvement (replacing N dependencies with 1) but would in principle have the same problem: a bunch of functions accepting a parameter only to forward it to other functions down the stack, without using it themselves.mock.patchfor unit testing (which I already use btw but hope to reduce/eliminate).Is there a better 3rd option?
Beta Was this translation helpful? Give feedback.
All reactions