DEV Community

Discussion on: Tell me a coding confession

Collapse
 
ld00d profile image
Brian Lampe

I like how IoC takes away the responsibility of layers to know about the creation of other layers (or their scope). Via DI, my controller can have a repository object injected by the IoC container, and the controller doesn't have to manage the lifecycle of the repository object.

Also, in unit tests, the repository object is easier to mock because I don't have my controller creating the instance in a constructor or something my test doesn't have access to.

DI can make things harder to read if the framework is limited to injecting interfaces and the interfaces have several implementations.