If have the code below, implementing the command pattern. I want to store several commands in a list and afterwards pick them from the list, resolve a commandhandler and finally execute the command.
When implementing this I ran into the problem, that resolving a single command worked from Autofac but resolving commands stored in the list raised an exception telling me the commandhandler could not be found even when it's the same command as I resolve the commandhandler before.
public static void ShowResolveProblem()
{
var action = new DisplayMessageAction("Hello");
var actionhandler = GetActionHandler(action); // this works well
var actions = new List<IAction>();
actions.Add(action);
actionhandler = GetActionHandler(actions[0]); // this throws exception
}
And this is the resolving method
private static IActionHandler<T> GetActionHandler<T>(T action) where T : IAction
{
var container = GetActionHandlerContainer();
return container.Resolve<IActionHandler<T>>();
}
Does anyone know how to get this running?