Say I've the following class definition:
public class CreateThingyController : ICreateThingyController
{
private readonly ICreateThingyHandler handler;
private ISomeBusinessRuleBehaviourDependingOnFlag rule;
public CreateThingyController(ICreateThingyHandler handler)
{
handler = handler;
}
public void CreateThingy(string something, bool flag)
{
if(flag) rule = new BlaImplementation()
else rule = new BoehImplementation
}
}
I really dislike setting the behaviour at runtime like this, so I'd like to leverage SimpleInjector for this. But since I only know what to pick at runtime, depending on some variable I have no idea how to approach this..
Any help would be greatly appreciated!
Edit: Oh, wow, I'm just now beginning the benefit of using a DI container. Awesome stuff.