-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Introduce TrybeHttpClientFactory for HTTP client creation inter…
…ception
- Loading branch information
Showing
4 changed files
with
61 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// This work is licensed under the terms of the MIT license. | ||
// For a copy, see <https://opensource.org/licenses/MIT>. | ||
|
||
using TrybeSDK.Api; | ||
using TrybeSDK.Frontend; | ||
|
||
namespace TrybeSDK; | ||
|
||
public interface ITrybeApiClientFactory | ||
{ | ||
ITrybeApiClient CreateApiClient(TrybeSettings settings, string name = TrybeApiConstants.DefaultTrybeApiClient); | ||
|
||
ITrybeFrontendClient CreateFrontendClient(TrybeSettings settings, string name = TrybeApiConstants.DefaultTrybeShopClient); | ||
} | ||
|
||
/// <summary> | ||
/// Provides factory services for creating Trybe client instances. | ||
/// </summary> | ||
public class TrybeApiClientFactory : ITrybeApiClientFactory | ||
{ | ||
readonly ITrybeHttpClientFactory _httpClientFactory; | ||
|
||
public TrybeApiClientFactory(ITrybeHttpClientFactory httpClientFactory) | ||
{ | ||
_httpClientFactory = Ensure.IsNotNull(httpClientFactory, nameof(httpClientFactory)); | ||
} | ||
|
||
public ITrybeApiClient CreateApiClient(TrybeSettings settings, string name = TrybeApiConstants.DefaultTrybeApiClient) | ||
=> new TrybeApiClient(_httpClientFactory.CreateHttpClient(name), settings); | ||
|
||
public ITrybeFrontendClient CreateFrontendClient(TrybeSettings settings, string name = TrybeApiConstants.DefaultTrybeShopClient) | ||
=> new TrybeFrontendClient(_httpClientFactory.CreateHttpClient(name), settings); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// This work is licensed under the terms of the MIT license. | ||
// For a copy, see <https://opensource.org/licenses/MIT>. | ||
|
||
namespace TrybeSDK; | ||
|
||
/// <summary> | ||
/// Provides factory methods for creating a HTTP client. | ||
/// </summary> | ||
public interface ITrybeHttpClientFactory | ||
{ | ||
/// <summary> | ||
/// Creates a HTTP client. | ||
/// </summary> | ||
/// <param name="name">The HTTP client name.</param> | ||
/// <returns>The HTTP client.</returns> | ||
HttpClient CreateHttpClient(string name); | ||
} | ||
|
||
public class TrybeHttpClientFactory(IHttpClientFactory clientFactory) : ITrybeHttpClientFactory | ||
{ | ||
public HttpClient CreateHttpClient(string name) | ||
=> Ensure.IsNotNull(clientFactory, nameof(clientFactory)).CreateClient(name); | ||
} |