public Result Dispatch(CommandInterface command) { Type type = typeof(CommandHandlerInterface <>); Type[] typeArgs = { command.GetType() }; Type commandHandlerType = type.MakeGenericType(typeArgs); dynamic handler = _provider.GetService(commandHandlerType); Result result = handler.Handle((dynamic)command); return(result); }