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
I am trying to implement the dependencies on other modules and cannot seem to figure out how to get the functions registered in modules a module is dependent on? Where should we store them? Should we store them inside the modules dependent as well?
My response: @cz2246 Very good question. This is one of the most important issues you have to solve when creating a dependency injection system. There are a few different ways you can handle this, but there are 3 things you have to consider when deciding how to get the functions registered in dependent modules:
Each module specifies its dependent modules at the time it is created.
At the time a module is created, it is not necessarily the case (in fact, it will rarely be the case) that all of the modules it requires as dependents have already registered all of their functions. This means that you can't simply add in all of another modules registered functions at the time you create your module.
Module dependencies may be circular. You need to make sure you can handle circular dependencies (and not loop forever).
In other words, each module needs to have a way to hold on to a reference to all of the modules that it depends on and, if it can't find a function in its registry, it needs to have a way to loop through its dependents until it finds that registered function (or fails to find it).
Make sense?
The text was updated successfully, but these errors were encountered:
If anyone else is new to this dependency injection concept, there is a Pluralsight course (albeit slowly paced...) that explains what dependency injection is and what it is doing. For our purposes I think you can watch skip ahead and watch the DI module. Thought I'd share -- here's the link: http://www.pluralsight.com/courses/inversion-of-control.
@cz2246 asked:
I am trying to implement the dependencies on other modules and cannot seem to figure out how to get the functions registered in modules a module is dependent on? Where should we store them? Should we store them inside the modules dependent as well?
My response:
@cz2246 Very good question. This is one of the most important issues you have to solve when creating a dependency injection system. There are a few different ways you can handle this, but there are 3 things you have to consider when deciding how to get the functions registered in dependent modules:
In other words, each module needs to have a way to hold on to a reference to all of the modules that it depends on and, if it can't find a function in its registry, it needs to have a way to loop through its dependents until it finds that registered function (or fails to find it).
Make sense?
The text was updated successfully, but these errors were encountered: