Recently I started working on a rather large monolithic system. The solution has web, app and api parts and in general just a lot of stuff.
It relies heavily on dependency injection and I noticed that this makes it really hard to figure out what’s happening.
A search for a controller name returns multiple results and when I finally figure out which one I need, some service is injected or otherwise located, and I have to start searching again.
By simply newing up an instance of an application service in a controller, the flow of the application is much easier to follow. I think it also lowers chances for runtime errors. Note that I’m not talking about adding any logic to the controllers, that is delegated to an application service layer.
Lastly, there aren’t any unit tests for the controllers, so I wondered: what am I missing here? Is there a benefit to DI I’m not aware of?
By simply newing up an instance of an application service
simply doing that in every single Controller which will have to know all the app service dependencies to instantiate the service, and the dependencies of the dependencies and so on... Simply duplicating code all over the application. A blatant violation of DRY.