public IRequestHandler <I, O, S, C, A> GetHandler <I, O>(IRequest <I, O> request)
 {
     // get or initialise handler. Safe to cast because init is generic.
     return(((IEnumerable <IRequestHandler <I, O, S, C, A> >)handlers
             .GetOrAdd(RequestKey.ForRequest(request), key =>
     {
         return InitHandler <I, O>(key);
     })).OrderBy(handler =>
     {
         RequestHandlerPriorityAttribute attr = handler.GetType().GetTypeInfo().GetCustomAttribute <RequestHandlerPriorityAttribute>();
         return attr == null ? 0 : attr.Priority;
     }).Where(handler => (handler is IConditionalHandler) ? ((IConditionalHandler)handler).CanHandle(request.Content) : true)
            .First());
 }
 public IRequestHandler <I, O, S, C, A> GetHandler <I, O>(IRequest <I, O> request)
 {
     // get or initialise handler. Safe to cast because init is generic.
     try
     {
         return(((IEnumerable <IRequestHandler <I, O, S, C, A> >)handlers
                 .GetOrAdd(RequestKey.ForRequest(request), key =>
         {
             return InitHandler <I, O>(key, false);
         })).OrderBy(handler =>
         {
             RequestHandlerPriorityAttribute attr = handler.GetType().GetTypeInfo().GetCustomAttribute <RequestHandlerPriorityAttribute>();
             return attr == null ? 0 : attr.Priority;
         }).Where(handler => (handler is IConditionalHandler) ? ((IConditionalHandler)handler).CanHandle(request.Content) : true)
                .First());
     }
     catch (InvalidOperationException e)
     {
         throw new ClientException($"No handler found for request {request.Namespace} {typeof(I).Name} {typeof(O).Name}", e);
     }
 }