/// <summary> /// Determine if the handler can handle the specified message given the specified query. /// </summary> /// <param name="message">The message.</param> /// <param name="query">The query.</param> /// <returns><c>true</c>, if the handler can handle the message; otherwise, <c>false</c>.</returns> public bool CanHandle(IMessage message, IQueryResponse query) { if (message == null || query == null) { return(false); } return(typeof(TMessage) == message.GetType() && typeof(TQuery) == query.GetType()); }
/// <summary> /// Gets the server message handlers that can handle the specified message and query. This method will /// intentionally throw an exception if no handlers could be found. /// </summary> /// <param name="message">The message.</param> /// <param name="query">The query.</param> /// <returns>A collection of message handlers.</returns> /// <exception cref="System.ArgumentException">Argument Exception.</exception> public IEnumerable <IServerMessageHandler> GetHandlers(IMessage message, IQueryResponse query) { if (!this.handlers.Any(h => h.CanHandleMessageType(message))) { throw new ArgumentException( $"Could not locate any server message handlers for the message type, '{message.GetType()}', " + $"and the query type, '{query.GetType()}'. Did you forget to write a server message handler?"); } var result = this.handlers.Where(x => x.CanHandle(message, query)).ToList(); return(result); }