public QueryHandlerProvider(Type type, QueryHandlerActionDescriptor actionDescriptor) { if (type == null) { throw new ArgumentNullException(nameof(type)); } _type = type; _actionDescriptor = actionDescriptor; }
public QueryHandlerInvoker(object handler, QueryHandlerActionDescriptor actionDescriptor, IServiceProvider serviceProvider) { if (handler == null) { throw new ArgumentNullException(nameof(handler)); } if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } _handler = handler; _actionDescriptor = actionDescriptor; _serviceProvider = serviceProvider; }
private bool TryGetHandlingMember(MethodInfo member, out QueryHandlerActionDescriptor result) { var parameters = member.GetParameters(); if (parameters.Length == 0) { result = default; return(false); } if (parameters.Any(p => p.ParameterType.IsByRef)) { result = default; return(false); } if (member.IsGenericMethod || member.IsGenericMethodDefinition) { result = default; return(false); } if (member.IsDefined <NoCommandHandlerActionAttribute>()) { result = default; return(false); } var commandType = parameters[0].ParameterType; var actionAttribute = member.GetCustomAttribute <CommandHandlerActionAttribute>(); if (actionAttribute != null && actionAttribute.CommandType != null) { if (!commandType.IsAssignableFrom(actionAttribute.CommandType)) { throw new InvalidOperationException(); } commandType = actionAttribute.CommandType; } // Synchronous handler if ((member.Name == "Handle" || actionAttribute != null) && (member.ReturnType == typeof(void) || !typeof(Task).IsAssignableFrom(member.ReturnType))) { result = new QueryHandlerActionDescriptor(commandType, member); return(true); } // Asynchronous handler if ((member.Name == "HandleAsync" || actionAttribute != null) && (typeof(Task).IsAssignableFrom(member.ReturnType))) { result = new QueryHandlerActionDescriptor(commandType, member); return(true); } result = default; return(false); }