refit icon indicating copy to clipboard operation
refit copied to clipboard

feature: Refit.HttpClientFactory overload AddRefitClient with Action Delegate

Open nazarkryp opened this issue 3 years ago • 0 comments

Is your feature request related to a problem? Please describe. Feature request is not related to the problem. It's rather a suggestion. Nowadays it's very convenient to pass action delegate when configuring something. In current case RefitSettings. As I don't have permissions to contribute and to create pull request to your wonderful library, I will describe suggested solution below

Describe the solution you'd like Solution: add method overload .AddRefitClient(this IServiceCollection services, Action<RefitSettings>? settingsAction = null), so developers could create client like in the following example

services.AddRefitClient<SomeClient>(settings => { settings.ExceptionFactory = message => Task.FromException<Exception?>(null); settings.ContentSerializer = new SystemTextJsonContentSerializer(); });

Describe suggestions on how to achieve the feature Feature can be achieved by adding appropriate extension method to HttpClientFactoryExtensions

public static IHttpClientBuilder AddRefitClient<T>(this IServiceCollection services, Action<RefitSettings>? settingsAction = null) where T : class { var settings = new RefitSettings(); settingsAction?.Invoke(settings); return AddRefitClient<T>(services, _ => settings); }

nazarkryp avatar Jun 09 '22 11:06 nazarkryp