I have a situation where the implementation of an interface is determined at runtime. For example, I check a string and then determine which subclass to use, without IoC it looks like the following:
if (fruitStr == "Apple")
{
new AppleImpl().SomeMethod();
}
else
{
new BananaImpl().SomeMethod();
}
Both classes AppleImpl
and BananaImpl
are implementation of the same interface, say IFruit
.
How can this be done using IoC/Dependency Injection, especially in Castle Windsor?