I’m new to DI and IoC pattern. I’m working on a new project and want to maximally loose couple my objects. My classes are split across several projects in solution. So I downloaded NInject and read somewhere that I should create bindings in application startup (Main function or Global.asax). One thing I don’t understand, is that in that case, I’ll have to reference those assemblies containing the classes to create binding, and this means that the classes is coupled with the object in which I create bindings. Is that right? Does this means that using MEF is a better idea? Anyone can explain how things work with IoC and why it’s a good idea to use it?
Thanks
I’m new to DI and IoC pattern. I’m working on a new project and
Share
Inversion of Control isn’t about not having references to assemblies, it’s more about creating contracts between your logic and dependent services. It facilitates testability and re-usability by abstracting out the concrete instantiation of your services when they are used.
This allows you, for example, to pass in a different data service that’ll save your data into an in-memory table instead of your database meaning that you’re not saving data to your database during unit tests. Your function that does the work doesn’t care what’s passed in because whatever it is, it implements a common interface that you can execute functions against with reasonable assumption that they’ll work.
There’s a bunch of good resources available to learn more about the IOC/DI pattern. Here’s a couple:
Ninject Sample
Wiki Article
And some site called “stack overflow”