private static TClient AddTransientHelper <TClient, TImplementation>(IServiceProvider s, IHttpClientBuilder builder) where TClient : class where TImplementation : class, TClient { IHttpClientFactory httpClientFactory = s.GetRequiredService <IHttpClientFactory>(); HttpClient httpClient = httpClientFactory.CreateClient(builder.Name); ITypedHttpClientFactory <TImplementation> typedClientFactory = s.GetRequiredService <ITypedHttpClientFactory <TImplementation> >(); return(typedClientFactory.CreateClient(httpClient)); }
internal static IHttpClientBuilder AddTypedClientCore <TClient>(this IHttpClientBuilder builder, bool validateSingleType) where TClient : class { ReserveClient(builder, typeof(TClient), builder.Name, validateSingleType); builder.Services.AddTransient <TClient>(s => { IHttpClientFactory httpClientFactory = s.GetRequiredService <IHttpClientFactory>(); HttpClient httpClient = httpClientFactory.CreateClient(builder.Name); ITypedHttpClientFactory <TClient> typedClientFactory = s.GetRequiredService <ITypedHttpClientFactory <TClient> >(); return(typedClientFactory.CreateClient(httpClient)); }); return(builder); }
internal static IHttpClientBuilder AddTypedClientCore <TClient, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] TImplementation>( this IHttpClientBuilder builder, bool validateSingleType) where TClient : class where TImplementation : class, TClient { ReserveClient(builder, typeof(TClient), builder.Name, validateSingleType); builder.Services.AddTransient <TClient>(s => { IHttpClientFactory httpClientFactory = s.GetRequiredService <IHttpClientFactory>(); HttpClient httpClient = httpClientFactory.CreateClient(builder.Name); ITypedHttpClientFactory <TImplementation> typedClientFactory = s.GetRequiredService <ITypedHttpClientFactory <TImplementation> >(); return(typedClientFactory.CreateClient(httpClient)); }); return(builder); }