A .NET 7+ class library and console application to fetch user data from a public API, featuring:
Clean Architecture: Separation of Core, Infrastructure, and Application layers.
HttpClientFactory + Polly: Typed ExternalUserService with retry policy for resilience.
Configuration: Strongly-typed options pattern (ApiSettings, CacheSettings).
In-Memory Caching: Configurable expiration for list and individual user calls.
Unit Tests: xUnit tests for service behavior.
/UserClient.sln
/src ├─ UserClient.Core # Models & Interfaces ├─ UserClient.Infrastructure # Implementation, Policies, Extensions └─ UserClient.ConsoleApp # Demonstration console application
tests └─ UserClient.Tests # Unit tests
.NET 7 SDK (or later)
Optional: Visual Studio 2022+, VS Code, JetBrains Rider
Internet access for hitting https://reqres.in/api
- In ConsoleApp, ensure appsettings.json exists: { "ApiSettings": { "BaseUrl": "https://reqres.in/api", "ApiKey": , "ApiKeyHeaderName": }, "CacheSettings": { "UserCacheDurationInMinutes": } }
2.Ensure the appsettings.json file is copied to output dir if newer.
Clean Architecture keeps domain models in Core, implementation details in Infrastructure, and no cross-dependencies.
HttpClientFactory: Ensures efficient socket reuse and integrates Polly policies seamlessly.
Polly Retry: Exponential backoff (2s, 4s, 8s) on transient failures.
In-Memory Cache: TTL-based caching.
Options Pattern: IOptions and IOptions for flexible configuration.