|
3 | 3 |
|
4 | 4 | namespace Aydsko.iRacingData;
|
5 | 5 |
|
6 |
| -internal sealed class CachingApiClient(ApiClient apiClient, |
| 6 | +internal sealed class CachingApiClient(IAuthenticatingHttpClient httpClient, |
| 7 | + iRacingDataClientOptions options, |
7 | 8 | IMemoryCache memoryCache,
|
8 | 9 | ILogger<CachingApiClient> logger,
|
| 10 | + ILogger<ApiClient> apiClientLogger, |
9 | 11 | TimeProvider timeProvider)
|
10 |
| - : IApiClient |
| 12 | + : IApiClient, IDisposable |
11 | 13 | {
|
| 14 | + private readonly ApiClient apiClient = new(httpClient, options, apiClientLogger); |
| 15 | + private bool disposedValue; |
| 16 | + |
12 | 17 | public async Task<DataResponse<(THeader, TChunkData[])>> CreateResponseFromChunksAsync<THeader, TChunkData>(Uri uri,
|
13 | 18 | bool isViaInfoLink,
|
14 | 19 | JsonTypeInfo<THeader> jsonTypeInfo,
|
@@ -161,4 +166,34 @@ public void UseUsernameAndPassword(string username, string password, bool passwo
|
161 | 166 | {
|
162 | 167 | apiClient.UseUsernameAndPassword(username, password, passwordIsEncoded);
|
163 | 168 | }
|
| 169 | + |
| 170 | + private void Dispose(bool disposing) |
| 171 | + { |
| 172 | + if (!disposedValue) |
| 173 | + { |
| 174 | + if (disposing) |
| 175 | + { |
| 176 | + // TODO: dispose managed state (managed objects) |
| 177 | + apiClient?.Dispose(); |
| 178 | + } |
| 179 | + |
| 180 | + // TODO: free unmanaged resources (unmanaged objects) and override finalizer |
| 181 | + // TODO: set large fields to null |
| 182 | + disposedValue = true; |
| 183 | + } |
| 184 | + } |
| 185 | + |
| 186 | + // // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources |
| 187 | + // ~CachingApiClient() |
| 188 | + // { |
| 189 | + // // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method |
| 190 | + // Dispose(disposing: false); |
| 191 | + // } |
| 192 | + |
| 193 | + public void Dispose() |
| 194 | + { |
| 195 | + // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method |
| 196 | + Dispose(disposing: true); |
| 197 | + GC.SuppressFinalize(this); |
| 198 | + } |
164 | 199 | }
|
0 commit comments