/// <summary> /// Given an interface, we find the Perimeter with whom the interface is registered. /// Using the Perimeter, we find an EndPointConfiguration that is alive. /// Using the EndPointType and ProviderName of the resolved EndPointConfiguration, we find an implementation of T. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public virtual T Create(params string[] overrideNames) { SetAvailableEndPoints(overrideNames); IEndPointConfiguration cachedEndPoint = CachedEndPoint; if (cachedEndPoint != null) { return(serviceFactory(cachedEndPoint.EndPointType, cachedEndPoint.ProviderName)); } foreach (T client in ClientEnumerator()) { IEndPointValidator validator = validatorFactory(CachedEndPoint.EndPointType, CachedEndPoint.ProviderName); if (!validator.IsInterfaceAlive(CachedEndPoint)) { if (logger != null) { logger($"Failed to connect to EndPoint named {CachedEndPoint.Name} when resolving a client of type {typeof(T)}."); } continue; } return(client); } throw new Exception($"A functional EndPointConfiguration could not be resolved for client of type {typeof(T).Name}.", null); }
public static IEndPointValidator ResolveValidator(this ResolutionHelper helper, string endPointType, string providerName) { IEndPointValidator result = null; result = helper.cxt.ResolveOptionalKeyed <IEndPointValidator>(endPointType + providerName); if (result == null) { throw new ComponentNotRegisteredException($"An attempt to resolve an EndPointValidator for EndPointType { endPointType } failed. Use the RegisterEndPointValidator method on the RegistrationHelper to register an EndPointValidator for each EndPointType."); } return(result); }
/// <summary> /// Given an interface, we find the Perimeter with whom the interface is registered. /// Using the Perimeter, we find an EndPointConfiguration that is alive. /// Using the EndPointType and ProviderName of the resolved EndPointConfiguration, we find an implementation of T. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> public virtual T Create(params string[] overrideNames) { SetAvailableEndPoints(overrideNames); IEndPointConfiguration cachedEndPoint = CachedEndPoint; if (cachedEndPoint != null) { return(serviceFactory(cachedEndPoint.EndPointType, cachedEndPoint.ProviderName)); } foreach (T client in ClientEnumerator()) { bool?validationResult = endPointCache.GetValidationResult(CachedEndPoint.Name); if (validationResult.HasValue) // .HasValue when validated previously { if (validationResult.Value) { return(client); } else { continue; } } IEndPointValidator validator = validatorFactory(CachedEndPoint.EndPointType, CachedEndPoint.ProviderName); bool isAlive = validator.IsInterfaceAlive(CachedEndPoint); endPointCache.SetValidationResult(CachedEndPoint.Name, isAlive); if (!isAlive) { logger?.Invoke($"Failed to connect to EndPoint named {CachedEndPoint.Name} when resolving a client of type {typeof(T)}."); continue; } return(client); } throw new Exception($"A functional EndPointConfiguration could not be resolved for client of type {typeof(T).Name}.", null); }