I understand what IoC containers are and have been reading up on Structure Map. The technology seems easy enough to use. My question is, what is the appropriate level of granularity for using an IoC container?
I see the following possible levels of application for IoC:
I know the answer to this question is "it depends", but from your experience, what does then answer depend on? Is project size a factor?
Furthermore, where doesn't IoC make sense to use?
The idea isn't to break dependencies between domain objects, it's to shield your domain from the outside world. Your domain objects should be about whatever business problem you are solving and not about databases, logging, caching, http contexts, rest services etc...
This article talks about moving responsibilities out of your objects and into the IoC container.
http://www.agileatwork.com/captcha-and-inversion-of-control/
I think it makes sense to use it when you know you will be writing a lot of unit tests as it makes the construction of those tests easier. Also, it allows you (via external configuration) to change the behavior of objects during runtime.
It doesn't make sense to use IoC on smaller projects or projects that don't need massive decoupling.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With