Код: Выделить всё
services.AddHttpClient();
services.AddRefitClient(new RefitSettings(new NewtonsoftJsonContentSerializer()))
.AddHttpMessageHandler()
.ConfigureHttpClient(c => c.BaseAddress = new Uri(configuration["App:MyServerUrl"]));
< /code>
Теперь, в моих проектах я хотел бы иметь что -то подобное: < /p>
services.AddServers(options =>
{
options.MyServerUrl = configuration["App:MyServerUrl"];
});
< /code>
Поэтому я пытаюсь создать следующее расширение: < /p>
public class ServerOptions
{
public string MyServerUrl { get; set; }
}
public static IServiceCollection AddServers(this IServiceCollection services,
Action configureOptions = null)
{
if (configureOptions is null)
return services;
services.AddHttpClient();
services.AddRefitClient(new RefitSettings(new NewtonsoftJsonContentSerializer()))
.AddHttpMessageHandler()
.ConfigureHttpClient(c => c.BaseAddress = new Uri(...));
return services;
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... extensions