When not to use IoC and DI? [closed]

About your question about having only one interface implementation. When you use IoC, it is still useful to use an interface. It will be much easier to create real unit tests (that doesn’t depend on the interface implementation to be working correctly) using mocks for these interfaces. The core of using IoC is making code easier to test. So, don’t use IoC if you don’t want to test, or already have a better plan on testing without it.

IMHO, DI and IoC increase in complexity comes is paid by having an easier to test and less coupled code. It’s easier to isolate the problems and to make future changes. You can control its behavior better too.

I can see when not to use an IoC container (as it results in configuration overhead). This would happen on small projects, where you can do it manually, instead of using a container. But I can’t see much loss from using DI, unless you’re not planning to test your code…

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)