public static IHttpClientFactoryBuilder ConfigurePrimaryHttpMessageHandler(this IHttpClientFactoryBuilder builder, Func <HttpMessageHandler> configureHandler) { if (configureHandler == null) { throw new ArgumentNullException(nameof(configureHandler)); } if (!builder.Services.IsRegistered <HttpClientFactoryOptions>()) { builder.Services.IocContainer.Kernel.Register( Component .For(typeof(HttpClientFactoryOptions)) .LifestyleTransient() .Named(builder.Name) .OnCreate(a => { var o = (HttpClientFactoryOptions)a; o.HttpMessageHandlerBuilderActions.Add(b => b.PrimaryHandler = configureHandler()); }) ); } //builder.Services.IocContainer.Kernel.ComponentCreated += Kernel_ComponentCreated; //var options = builder.Services.IocContainer.Resolve<HttpClientFactoryOptions>(builder.Name); //options.HttpMessageHandlerBuilderActions.Add(b => b.PrimaryHandler = configureHandler()); return(builder); }
public static IHttpClientFactoryBuilder ConfigureHttpClient(this IHttpClientFactoryBuilder builder, Action <HttpClient> configureClient) { if (builder == null) { throw new ArgumentNullException(nameof(builder)); } if (configureClient == null) { throw new ArgumentNullException(nameof(configureClient)); } if (!builder.Services.IsRegistered <HttpClientFactoryOptions>()) { builder.Services.IocContainer.Kernel.Register( Component .For(typeof(HttpClientFactoryOptions)) .LifestyleTransient() .Named(builder.Name) .OnCreate(a => AddOptionsHttpClientActions((HttpClientFactoryOptions)a, configureClient)) ); } //builder.Services.IocContainer.Kernel.ComponentCreated += HttpClientOptionsComponentCreated; return(builder); }