Up or Down?
I'm a very visual person. I'm thinking of my application as a hierarchy, where the top is the root and the bottom is a leaf.
I'm also under the understanding that IoC containers are ignorant of their contained objects' responsibilities/functions. Instead, the contained objects know about their container, i.e. "context", via some abstracted interface.
UP: (The non-IoC way?) Should my events be dispatched from the bottom of my hierarchy and bubble upwards via a Chain-of-Responsibility pattern to their parents so that the contained objects are unaware of their containers? E.g. a button in my GUI dispatches a CLICKED event, which is caught by a listening container window that responds by closing itself.
DOWN: (The IoC way?) Should my events be dispatched from the top of my hierarchy by a container and reach contained listeners that have subscribed directly to the container so that the containers are unaware of their contents? E.g. a container window dispatches a CLOSED event, which is received directly by contained button objects that respond by closing themselves and then the window follows suit by closing itself.
'Up' seems natural to me, but since IoC has a container being unaware of its contained objects' behavior, I wouldn't want to respond to their events.
I realize it's POSSIBLE to have nearly any part of a system listen to an event, but I want to understand the fundamental relationship between IoC participants, so I can structure them properly. I'm assuming people don't usually just scatter events about their program without regard to structural relationships, dependencies, etc.
My question arises from the responsibility placement in an IoC system -- it's the contained object's responsibility to make calls on the container and the container's responsibility to provide services to its dependent objects (which inverts the non-IoC paradigm -- hence the synonym "Dependency Inversion"). This seems to be a very important, fundamental component of IoC -- a shifting of responsibilities. I consider calling an object's functions or listening to its events to BOTH be examples of depending on another object. When an object defines its own behavior based on another object, I call that a dependency because one object KNOWS of the other and also KNOWS what the other does. It has defined itself within the context of the other object. As I understand, IoC is set up so that the contained object is dependent on the container, so it should be the contained object's responsibility to know all about the container. And it should NOT be the container's responsibility to know about the contained object. So, for the CONTAINER to be listening to events on the CONTAINED injected object seems to me like like a misplacement of responsibilities because that means it knows something about its contents.
This question has been re-phrased after learning Dependency 'Injection' and 'Inversion' are different. Previous question found here.