On the IOC Castle Windsor wiki [Editor's Note: After this question was written, the wiki has been updated with more example code], there is the following (incomplete) demo code.
How do I complete this code so it runs properly in a C# console app?
//application starts...
var container = new WindsorContainer();
// adds and configures all components using WindsorInstallers from executing assembly
container.Install(FromAssembly.This());
// instantiate and configure root component and all its dependencies and their dependencies and...
var king = container.Resolve<IKing>();
king.RuleTheCastle();
// clean up, application exits
container.Dispose();
Update:
Discovered tutorial videos on IOC in general.
Got as far as adding an interface and a concrete implementation of the interface:
interface IKing
{
void RuleTheCastle();
}
public class King
{
void RuleTheCastle()
{
Consolel.Write("Rule the castle.");
}
}
However, it threw a runtime error when I ran it.
Update:
I ended up using Ninject, because:
- The documentation is far superior to Castle Windsor (and Spring.NET for that matter).
- It uses expression compilation/LCG, so its faster (8x to 50x) compared to Castle Windsor, which uses Reflection.
To get started, click on "Visit the Dojo", then follow through the series of NInject tutorials on GitHub.
After you've done this, you can view a tutorial video on TekPub. The video does go through the concepts quite fast, so it might be good to complete the series of NInject tutorials on GitHub first.