public ICommand Create(IArguments arguments) { var commandType = typeof(ICommandWithArguments<>); var genericType = commandType.MakeGenericType(arguments.GetType()); var command = _dependancyContainer.Resolve(genericType); if (command == null) return null; var compiledCommandType = typeof(CompiledCommand<,>); var genericCompiledCommandType = compiledCommandType.MakeGenericType(genericType, arguments.GetType()); var result = (ICommand) Activator.CreateInstance(genericCompiledCommandType, command, arguments); return result; }
public virtual Task <ArgumentsHandlerResponse> Handle(IArguments arguments, CancellationToken cancellationToken = default) { if (arguments == null) { throw new ArgumentNullException(nameof(arguments)); } if (!(arguments is T handlerArguments)) { throw new NotSupportedException($"{arguments.GetType().Name} are not supported."); } return(Handle(handlerArguments, cancellationToken)); }