Events in the dependency injection system go in which direction?

Up or down?

I am a very visual person. I see my application as a hierarchy, where the top is the root and the bottom is the leaf.

I also understand that on DI systems, containers do not know the responsibilities / functions of their contained objects. Instead, the contained objects know their context, because context (dependency) is introduced into it.

UP: (non-DI method)?
Should my events go from my lower hierarchy and bubble up to their parents? For example. a button in my GUI dispatches an event CLICKEDthat is captured by the listening container, which responds by performing the appropriate action.

DOWN: (path DI)

Should my events be sent from the top of my hierarchy by a parent who his children are listening to? For example. -... well, I have problems with this. I think along the lines of an intermediary that sends events for contained objects.

'Up' seems natural to me, but since DI does not have a container that is unaware of the behavior of its contained objects, I would not want to respond to their events.

EDIT (specify):

I understand that it is possible that almost any part of the system listens for an event, but I want to understand the fundamental relationships between DI participants, so I can structure them correctly. I assume that people usually do not just scatter events about their program without taking into account structural relationships, dependencies, etc.

- DI - ( -DI - , " " " " ). , -, , DI - . , BOTH . , , , KNOWS , , . . , DI , , , . . , , , , , - .

, , .

+3
6

. , , , .

, . , Clicked, . .

, . , . .

, . , Clear() . , , .

, , (, , ). , , , . .

, . , , , , , . , , .

, , . . , . . Injection Dependency . " " " ", , . , . B, , A ( ), .

+3

, , , , .

, .

, , - , - , .

, , , .

+1

Observer , "" , "" - , / , . , , -, , .

EDIT: Observer

+1

, . , , , , - . "". , . , ..

, . , :

interface IEventHandler {
    void setNextHandler(IEventHandler nextHandler);
    void handleEvent(Event e);
}
+1

- , . ?

, - .., , . / Tx/Rx; , , , - .. , , - . , , . , , , . , . (, ACK) . , . " ", , -. .. .

So, in such systems, you will agree that events must go up from below.

Up or down, it is up to your chosen model.

See also for the highly competitive model described in duocent "EffoNetMsg.pdf" at http://code.google.com/p/effonetmsg/downloads/list .

0
source

How to pass event similarly to WPF binding?

0
source

Source: https://habr.com/ru/post/1719680/


All Articles