I have a small project that has 6 service classes and a main class. Since they are service classes and does not store any state in it, I declared one static method in each one:
- class Main calls A.foo1(param)
- A calls (in static foo1 method) B.foo2(param2)
- B calls (in static foo2 method) C.foo3(param3)
- and so on...
Recently I've decided to apply dependency injection with constructor injection.
First, I changed static methods to normal methods and I had to create a huge A
object in main:
new A(new B(new C(new D(new E(...)))));
Is there a cleaner way to achieve this? It seems ugly to me and using Spring (Java's popular framework containing DIC) for only 6 classes seems unnecessary.