I’m studying Enterprise Patterns and I’m reading this book.
I just read chapter 5 and I’m still confused… As far as I understood, IoC is supposed to remove dependencies from other classes, right? aka Loosely Coupling.
And I also read that this is good because if you rebuild your concrete classes, it won’t break the objects that has dependencies on it.
I understood that it meant, if I rebuild the assembly (.dll) it won’t require me to rebuild the other projects referencing it, is that correct?
But the sample in the book references it in the project, and do a lot of things to get an instance of a class, this is what makes me confused.
I thought that the final result would be something that dynamically loads the assembly and creates instances of concrete classes inside it, something like MEF.
Can somebody explain me this?
IoC is not just for removing dependencies. Your assemblies and classes are not tightly coupled. And you can replace them each time you want.
But one of the main approaches is to change dependencies and used classes and objects at runtime. You can ask your IoC Container to provide you a business handler class and you do not need to care what class is returned to you. The IoC Container will decide of which class to return an instance and you can provide this logic for it.
IoC (DI) removes tightly coupled dependencies and also has some logic for creating different object types, handlers, business providers based on each situation and there is no need for you to care about them at runtime.
IoC in WikiPedia
What problems does it try to solve?
Benefits