Skip to content

Commit

Permalink
7 http client di (#8)
Browse files Browse the repository at this point in the history
* #7 - Changed DI for the http client

* #7 - Changed location of base URL for the client

---------

Co-authored-by: Eduard Keilholz <e.keilholz@4dotnet.nl>
  • Loading branch information
nikneem and Eduard Keilholz committed May 6, 2024
1 parent c335552 commit 27a83d8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ public static IServiceCollection AddSessionizeApiClient(this IServiceCollection
throw new SessionizeApiClientException(ErrorCode.InvalidConfiguration);
}

services.AddHttpClient(SessionizeConstants.HttpClientName, client =>
{
client.BaseAddress = new Uri(sessionizeConfiguration.BaseUrl);
client.Timeout = TimeSpan.FromSeconds(10);
})
services.AddHttpClient<SessionizeApiClient>()
.AddStandardResilienceHandler();

services.AddScoped<ISessionizeApiClient, SessionizeApiClient>();
Expand Down
3 changes: 2 additions & 1 deletion src/Sessionize.Api.Client/SessionizeApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public Task<List<SpeakerWallDto>> GetSpeakerWallAsync()

private async Task<TResult> SendRequestAsync<TResult>(string endpoint)
{
var httpClient = _httpClientFactory.CreateClient(SessionizeConstants.HttpClientName);
var httpClient = _httpClientFactory.CreateClient();
httpClient.BaseAddress = new Uri(_sessionizeConfiguration.Value.BaseUrl);
_logger.LogInformation("Sending GET request to endpoint {Endpoint}", GetViewEndpoint(endpoint));
var response = await httpClient.SendAsync(GetRequest(endpoint));
response.EnsureSuccessStatusCode();
Expand Down
6 changes: 0 additions & 6 deletions src/Sessionize.Api.Client/SessionizeConstants.cs

This file was deleted.

0 comments on commit 27a83d8

Please sign in to comment.