InversifyJS icon indicating copy to clipboard operation
InversifyJS copied to clipboard

how to use `containerModule` to resolve dependencies from multiple top level modules ?

Open yichong96 opened this issue 3 years ago • 0 comments

I have a dependency diagram as such in my application. I want to use the containerModule api of inversify to load my dependencies.

enter image description here

The dependency is from A -> B and C -> B. However, inversify does not allow for 'duplicate bindings'.

Suppose module D(the top level module) depends on Module A and C, then I would try to build the dependency graph from the bottom up starting from B -> (A + C) -> D. However, If I load containerModule B from containerModule A and containerModule C, and proceed to load containerModule A and containerModule C in containerModule D, I would have ambiguous bindings when I try to resolve my dependencies in in containerModule D because I would have loaded B dependencies twice in A and C.

What would be a best practice for dealing with such a situation ? I believe it would be quite common in OO applications.

yichong96 avatar Jun 14 '22 11:06 yichong96