Skip to content

Commit

Permalink
Fix lifetime problem with HttpClientInterceptorOptions
Browse files Browse the repository at this point in the history
  • Loading branch information
shaynevanasperen committed Jan 5, 2021
1 parent 7842d8e commit 44fd505
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public static class HttpRequests
/// <summary>
/// Returns a new <see cref="HttpRequestInterceptionBuilder"/>.
/// </summary>
public static HttpRequestInterceptionBuilder Intercept => new HttpRequestInterceptionBuilder();
public static HttpRequestInterceptionBuilder Intercept => new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ public static class ServiceCollectionExtensions
/// are isolated.
/// </summary>
/// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param>
/// <param name="options">The <see cref="HttpClientInterceptorOptions"/> to use for configuring the interceptions.</param>
/// <param name="optionsFactory">The factory for creating the <see cref="HttpClientInterceptorOptions"/> to use for configuring the interceptions.</param>
/// <returns>A reference to this instance after the operation has completed.</returns>
public static IServiceCollection AddHttpRequestInterceptor(this IServiceCollection services, HttpClientInterceptorOptions options)
public static IServiceCollection AddHttpRequestInterceptor(this IServiceCollection services, Func<IServiceProvider, HttpClientInterceptorOptions> optionsFactory)
{
if (services == null) throw new ArgumentNullException(nameof(services));

services.AddSingleton(options);
services.AddSingleton(optionsFactory);
services.AddSingleton<IHttpMessageHandlerBuilderFilter, HttpInterceptionFilter>();
services.AddTransient<ITestScopeProducer>(provider =>
new TestScopeProducer<IDisposable>(provider.GetRequiredService<HttpClientInterceptorOptions>().BeginScope, x => x.Dispose));
Expand Down

0 comments on commit 44fd505

Please sign in to comment.