private IHalHttpClient CreateHalHttpClient(HttpClient httpClient, T context) { var wrapped = new HalHttpClient(HalJsonParser, httpClient); try { Configure(wrapped.Configuration, context); var decorated = Decorate(wrapped, context) ?? wrapped; return(decorated); } catch (Exception) { wrapped.Dispose(); // client is unusable ... throw; } }
private async Task <IHalHttpClient> CreateHalHttpClientAsync(HttpClient httpClient, T context, CachingBehavior apiRootCachingBehavior) { if (httpClient == null) { throw new ArgumentNullException(nameof(httpClient)); } var wrapped = new HalHttpClient(HalJsonParser, httpClient); try { Configure(wrapped.Configuration, context); var decorated = Decorate(wrapped, context) ?? wrapped; switch (apiRootCachingBehavior) { case CachingBehavior.Never: break; case CachingBehavior.PerClient: var apiRootResource = await GetFreshRootResourceAsync(decorated, wrapped.Configuration).ConfigureAwait(false); wrapped.CachedApiRootResource = apiRootResource; break; case CachingBehavior.Once: _cachedApiRootResource = _cachedApiRootResource ?? await GetFreshRootResourceAsync(decorated, wrapped.Configuration).ConfigureAwait(false); wrapped.CachedApiRootResource = _cachedApiRootResource; break; default: throw new ArgumentOutOfRangeException(nameof(apiRootCachingBehavior), apiRootCachingBehavior, null); } return(decorated); } catch (Exception) { wrapped.Dispose(); // client is unusable ... throw; } }
private IHalHttpClient CreateHalHttpClient(HttpClient httpClient) { if (httpClient == null) { throw new ArgumentNullException(nameof(httpClient)); } var wrapped = new HalHttpClient(HalJsonParser, httpClient); try { Configure(wrapped.Configuration); var decorated = Decorate(wrapped) ?? wrapped; return(decorated); } catch (Exception) { wrapped.Dispose(); // client is unusable ... throw; } }