Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Post History
Refit allows such configuration out of the box bt using AddRefitClient (which resembles the well-known AddHttpClient). This indeed requires explicit configuration for the HttpClient, but the config...
Answer
#1: Initial revision
Refit allows such configuration out of the box bt using `AddRefitClient` (which resembles the well-known AddHttpClient). This indeed requires explicit configuration for the HttpClient, but the configuration and usage will be simpler: ### Refit and resilience configuration ```c# private static IServiceCollection ConfigureResilience(this IServiceCollection services) { services .AddRefitClient(typeof(IBarIntegration), (sp) => { var accessTokenHelperService = sp.GetRequiredService<IAccessTokenHelperService>(); return new RefitSettings { AuthorizationHeaderValueGetter = () => accessTokenHelperService.GetAccessToken(default) }; }) .ConfigureHttpClient((sp, client) => { var BarSettings = sp.GetRequiredService<IOptions<BarApiSettings>>(); string baseUrl = BarSettings.Value.BaseUrl; client.BaseAddress = new Uri(baseUrl); }) .AddTransientHttpErrorPolicy(policyBuilder => policyBuilder.WaitAndRetryAsync( Backoff.DecorrelatedJitterBackoffV2(TimeSpan.FromSeconds(1), RetryPolicyMaxCount) ) ); .WaitAndRetryAsync(Backoff.DecorrelatedJitterBackoffV2(TimeSpan.FromSeconds(1), RetryPolicyMaxCount))); return services; } ``` ### Refit interface ```c# [Headers("Authorization: Bearer")] public interface IBarIntegration { [Get("/api/ext/Foo/GetFooBriefInfo")] Task<GetFooBriefInfoForFooDto> GetFooBriefInfo(GetFooBriefInfoForFooInputDto inputData); } ```