I am refactoring my code and moving some classes to an external assembly. In my projects I use Refit and currently I set it up like this in Startup:
services.AddHttpClient();services.AddRefitClient<IMyServerService>(new RefitSettings(new NewtonsoftJsonContentSerializer())) .AddHttpMessageHandler<MyServerHandler>() .ConfigureHttpClient(c => c.BaseAddress = new Uri(configuration["App:MyServerUrl"]));Now, in my projects I would like to have something like this:
services.AddServers(options =>{ options.MyServerUrl = configuration["App:MyServerUrl"];});So I am trying to create the following extension:
public class ServerOptions{ public string MyServerUrl { get; set; }}public static IServiceCollection AddServers(this IServiceCollection services, Action<ServerOptions> configureOptions = null){ if (configureOptions is null) return services; services.AddHttpClient(); services.AddRefitClient<IMyServerService>(new RefitSettings(new NewtonsoftJsonContentSerializer())) .AddHttpMessageHandler<MyServerHandler>() .ConfigureHttpClient(c => c.BaseAddress = new Uri(...)); return services;}How do I correctly set up the configuration options so the the property is passed to the based address of the HttpClient?