0

Let's assume our program has 2 layers: A (user interface) and B (does the actual work).

IF I understand DIP correctly, then:

Without using DI the layer A would depend on concrete implementations provided by layer B. With DIP applied the layer A would define abstract interface which layer B would implement. Then using dependency injection the layer B would pass these implementations to the layer A.

My question is:

Should the program's entry point (main() function) be in layer A, or B?

I'm not sure if my reasoning is correct, but I think that if the main() would be in A layer, then there would be a cycle of dependency. On the other hand main() in the layer B feels somehow counter-intuitive to me.

marc_s
  • 675,133
  • 158
  • 1,253
  • 1,388
Pawlakov
  • 27
  • 2
  • 7
  • In most cases B would have the interface **and** the implementation. What makes you think that DI changes that? Which IoC container are you planning to use? – mjwills Jun 21 '18 at 21:23
  • Did you mean "where should I keep the composition root?" There are plenty of articles on SO with clarification. e.g. https://stackoverflow.com/questions/1410719/design-where-should-objects-be-registered-when-using-windsor/1410738#1410738 – vendettamit Jun 21 '18 at 22:10
  • That's backward. With DI, layer B would define interfaces, layer A would implement them, and pass those implementations to layer B at run time. The programs entry point would generally be in layer A. – glenebob Jun 21 '18 at 23:38
  • The example in the question might lead to confusion ; the description of dependencies between the UI and B is not obvious nor standard. – Emond Erno Jun 22 '18 at 04:27

0 Answers0