General questions are welcome, but is there any reason not to post each one under its own topic? Seems like that would be more modular than mashing up multiple questions into one thread.
Regarding your question, there are relevant wikipedia pages. Let's start with:
http://en.wikipedia.org/wiki/Inversion_of_controlI think it's notable that the "Background" section of that page says "It is still undecided if Inversion of Control is a design pattern, an architectural principle, or both." followed by some additional notes which do little to clarify things. I'm doubtful that learning all the nuances of what terms people have used and why is useful in day to day development. I think it's much easier to come in via the "dependency injection" term:
http://en.wikipedia.org/wiki/Dependency_InjectionAlthough then you have to deal with the fact that supporting libraries are called "IoC containers". One that looks interesting to me is Autofac:
http://code.google.com/p/autofac/Essentially instead of hard coding class instantiation like so:
- Code: Select all
// C#
var taskController = new TaskController();
You abstract the creation of objects like so:
- Code: Select all
var taskController = container.Resolve<IController>();
And now you can configure what is created for resolving an IController. This is useful for managing multiple environments (local, dev, test, production) as well as unit testing (think "mock objects").
In some notes from 2009-09, I have this about Autofac:
-- When instantiating classes, Autofac will choose the constructor with the most resolvable parameters.
-- Autofac will recursively resolve dependencies.
-- If dependencies cannot be resolved, a useful error message is provided.
(These are all good things.)
That being said, I haven't played with it in practice and haven't used dependency injection much in my enterprise apps.
Looking at the Autofac project page today, it appears that the project is still alive and healthy. Maybe you'd like to play with it from C# and Cobra and share your findings?