How ehsanfaridi92/refitwithpolly works
Main Components
• Application Entry Point: Highlight Program.cs, which bootstraps the application.
• Configuration Layer: Include a component for configuration, drawing from files such as appsettings.json and the Configuration folder (with ApiResourceConfiguration.cs and WaitAndRetryConfig.cs) that set up API resources and retry settings.
• HTTP Client Component (Refit):
• “Refit” folder components — notably ICharactersService.cs which defines the interface for HTTP operations.
• CharactersDecorator.cs which suggests additional layers (like logging or wrapping of HTTP call logic).
• Role of Refit in abstracting HTTP communication.
• Resilience and Policy Component (Polly):
• Mechanism for retry and circuit breaker policies that govern the HTTP calls.
• Authentication Handler:
• A dedicated Authentication Handler component (e.g., ApiResourceAuthenticationHandler.cs) in the Refit/AuthenticationHandler folder which manages authorization aspects for API requests.
Relationships and Interactions
• How the configuration layer feeds into setting up both the Refit HTTP client and Polly policies.
• Authentication Handler as an intermediary that intercepts or enriches outgoing HTTP requests with necessary authorization tokens or headers.
Architectural Patterns and Design Principles
• Separation of Concerns: Clearly distinguish between configuration, HTTP request generation (Refit), and resiliency logic (Polly).
• Middleware/Interceptor Pattern: Emphasize the use of the Authentication Handler and CharactersDecorator as middleware shaping the outgoing/incoming request flow.
Relevant Technologies and Frameworks
• .NET Core: The underlying framework.
• Refit: For simplicity in consuming REST APIs.
• Polly: For implementing resilience strategies like retries and circuit breakers.
• Configuration files (appsettings.json) and custom configuration classes for API resource and policy settings.