Coder Social home page Coder Social logo

Comments (4)

xljiulang avatar xljiulang commented on June 28, 2024

WebApiClient支持包装HttpClientFactory所创建的HttpClient,可以在代码里加入如下扩展方法:

public static IHttpClientBuilder AddHttpApiClient<TInterface>(this IServiceCollection services, Action<HttpApiConfig> config = null)
        where TInterface : class, IHttpApi
{
    return services.AddHttpClient(typeof(TInterface).Name).AddTypedClient<TInterface>((client, provider) =>
    {
        var httpApiConfig = new HttpApiConfig(client);
        config?.Invoke(httpApiConfig);
        return HttpApiClient.Create<TInterface>(httpApiConfig);
    });
}

from webapiclient.

ghd258 avatar ghd258 commented on June 28, 2024

关于HttpClientFactory 到底解决了那些HttpClient的严重问题

  (1)在处理HttpClient对象的时候不会立即关闭socket。

  (2)太多的实例影响性能

  (3)单例的HttpClient或者共享HttpClient实例,不遵守DNS 生存时间 (TTL) 设置。

from webapiclient.

xljiulang avatar xljiulang commented on June 28, 2024

@ghd258
现在写了一个个WebApiClient扩展项目,有对HttpClientFactory的直接扩展
https://github.com/xljiulang/WebApiClient.Extensions

from webapiclient.

gitlsl avatar gitlsl commented on June 28, 2024

https://blogs.msdn.microsoft.com/webdev/2018/10/17/asp-net-core-2-2-0-preview3-now-available/
可以等下个月正式发布的2.2 httpclient 性能提升很多

from webapiclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.