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