Ejemplo n.º 1
0
 public BusBase()
 {
     _handlers = new ConcurrentKeyedCollection(50);
 }
Ejemplo n.º 2
0
        private ResponderBase <TRequest> GetResponder <TRequest, UResponse>(TRequest request, ConcurrentKeyedCollection collection)
        {
            List <IDisposable> responders;
            var topic = GetCombinedTopic <TRequest, UResponse>();

            if (collection.TryGet(topic, out responders))
            {
                var filteredResponders = responders.Cast <ResponderBase <TRequest> >().Where(r => r.CanRespond(request));

                if (filteredResponders.Count() != 1)
                {
                    throw new InvalidOperationException($"There should be one and only responder for <{typeof(TRequest).FullName},{typeof(TRequest).FullName}>");
                }

                return(filteredResponders.First());
            }
            else
            {
                throw new InvalidOperationException($"No responders found for <{typeof(TRequest).FullName},{typeof(UResponse).FullName}>");
            }
        }