Ejemplo n.º 1
0
        public async Task <HttpClient> GetClient <T>()
        {
            var eventLocation = await _statusRepository.GetEventLocation();

            var type = typeof(T);

            if (type.GetGenericTypeDefinition() == typeof(AsyncEventHandler <,>) ||
                type.GetGenericTypeDefinition() == typeof(QueryEventHandler <,>))
            {
                var eventType           = type.GetGenericArguments().Last();
                var domainEventLocation = eventLocation.GetServiceForEvent(eventType);
                if (domainEventLocation == null)
                {
                    return(DefaultHttpClient());
                }
                var httpClient = await _httpClientFactory.CreateHttpClient(domainEventLocation.ServiceEndPoint.ServiceBaseAddress);

                httpClient.BaseAddress = new Uri(domainEventLocation.ServiceEndPoint.ServiceBaseAddress + $"Api/DomainEventTypeStreams/{eventType.Name}");
                return(httpClient);
            }
            else
            {
                var readModelType = type.GetGenericArguments().First();
                var subscriberEventAndReadmodelConfig = eventLocation.GetServiceForReadModel(readModelType);
                if (subscriberEventAndReadmodelConfig == null)
                {
                    return(DefaultHttpClient());
                }
                var httpClient = await _httpClientFactory.CreateHttpClient(subscriberEventAndReadmodelConfig.ServiceEndPoint.ServiceBaseAddress);

                httpClient.BaseAddress = new Uri(subscriberEventAndReadmodelConfig.ServiceEndPoint.ServiceBaseAddress + "Api/DomainEvents");
                return(httpClient);
            }
        }
        public async Task <HttpClient> GetClient(Uri serviceAddress)
        {
            var discoveryClient = await _clientFactory.CreateHttpClient(serviceAddress);

            discoveryClient.BaseAddress = serviceAddress;
            return(discoveryClient);
        }