Exemple #1
0
        /// <summary>
        /// http上下文
        /// </summary>
        /// <param name="httpClient">httpClient实例</param>
        /// <param name="serviceProvider">服务提供者</param>
        /// <param name="httpApiOptions">Api配置选项</param>
        /// <exception cref="ArgumentNullException"></exception>
        public HttpContext(HttpClient httpClient, IServiceProvider serviceProvider, HttpApiOptions httpApiOptions)
            : base(httpClient, serviceProvider, httpApiOptions)
        {
            var requiredUri = httpApiOptions.HttpHost ?? httpClient.BaseAddress;

            this.RequestMessage     = new HttpApiRequestMessage(requiredUri, httpApiOptions.UseDefaultUserAgent);
            this.CancellationTokens = new List <CancellationToken>();
        }
Exemple #2
0
 /// <summary>
 /// http上下文
 /// </summary>
 /// <param name="client">httpClient</param>
 /// <param name="services">服务提供者</param>
 /// <param name="options">接口选项</param>
 /// <exception cref="ArgumentNullException"></exception>
 public HttpContext(HttpClient client, IServiceProvider services, HttpApiOptions options)
 {
     this.Client         = client ?? throw new ArgumentNullException(nameof(client));
     this.Services       = services ?? throw new ArgumentNullException(nameof(services));
     this.Options        = options ?? throw new ArgumentNullException(nameof(options));
     this.RequestMessage = new HttpApiRequestMessage {
         RequestUri = options.HttpHost ?? client.BaseAddress
     };
 }
 /// <summary>
 /// 创建THttpApi的代理实例
 /// </summary>
 /// <typeparam name="THttpApi"></typeparam>
 /// <param name="httpClient">httpClient</param>
 /// <param name="serviceProvider">服务提供者</param>
 /// <param name="httpApiOptions">Api配置选项</param>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="NotSupportedException"></exception>
 /// <exception cref="ProxyTypeCreateException"></exception>
 /// <returns></returns>
 public static THttpApi Create <THttpApi>(HttpClient httpClient, IServiceProvider serviceProvider, HttpApiOptions httpApiOptions)
 {
     return(Create <THttpApi>(new HttpClientContext(httpClient, serviceProvider, httpApiOptions)));
 }
Exemple #4
0
 /// <summary>
 /// HttpClient上下文
 /// </summary>
 /// <param name="httpClient">httpClient实例</param>
 /// <param name="serviceProvider">服务提供者</param>
 /// <param name="httpApiOptions">Api配置选项</param>
 /// <param name="optionsName">选项名称</param>
 /// <exception cref="ArgumentNullException"></exception>
 public HttpClientContext(HttpClient httpClient, IServiceProvider serviceProvider, HttpApiOptions httpApiOptions, string optionsName)
 {
     this.HttpClient      = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
     this.ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     this.HttpApiOptions  = httpApiOptions ?? throw new ArgumentNullException(nameof(httpApiOptions));
     this.OptionsName     = optionsName ?? string.Empty;
 }
Exemple #5
0
 /// <summary>
 /// HttpClient上下文
 /// </summary>
 /// <param name="httpClient">httpClient实例</param>
 /// <param name="serviceProvider">服务提供者</param>
 /// <param name="httpApiOptions">Api配置选项</param>
 /// <exception cref="ArgumentNullException"></exception>
 public HttpClientContext(HttpClient httpClient, IServiceProvider serviceProvider, HttpApiOptions httpApiOptions)
     : this(httpClient, serviceProvider, httpApiOptions, string.Empty)
 {
 }
Exemple #6
0
 /// <summary>
 /// http上下文
 /// </summary>
 /// <param name="client">httpClient</param>
 /// <param name="services">服务提供者</param>
 /// <param name="options">接口选项</param>
 /// <exception cref="ArgumentNullException"></exception>
 public HttpContext(HttpClient client, IServiceProvider services, HttpApiOptions options)
     : base(client, services, options)
 {
     this.RequestMessage = new HttpApiRequestMessage(options.HttpHost ?? client.BaseAddress);
 }
Exemple #7
0
 /// <summary>
 /// http上下文
 /// </summary>
 /// <param name="httpClient">httpClient实例</param>
 /// <param name="serviceProvider">服务提供者</param>
 /// <param name="httpApiOptions">Api配置选项</param>
 /// <exception cref="ArgumentNullException"></exception>
 public HttpContext(HttpClient httpClient, IServiceProvider serviceProvider, HttpApiOptions httpApiOptions)
     : base(httpClient, serviceProvider, httpApiOptions)
 {
     this.CancellationTokens = new List <CancellationToken>();
     this.RequestMessage     = new HttpApiRequestMessage(httpApiOptions.HttpHost ?? httpClient.BaseAddress);
 }
 /// <summary>
 /// 服务上下文
 /// </summary>
 /// <param name="client"></param>
 /// <param name="services"></param>
 /// <param name="options"></param>
 /// <exception cref="ArgumentNullException"></exception>
 public ServiceContext(HttpClient client, IServiceProvider services, HttpApiOptions options)
 {
     this.Client   = client ?? throw new ArgumentNullException(nameof(client));
     this.Services = services ?? throw new ArgumentNullException(nameof(services));
     this.Options  = options ?? throw new ArgumentNullException(nameof(options));
 }
Exemple #9
0
        /// <summary>
        /// 创建THttpApi的代理实例
        /// </summary>
        /// <typeparam name="THttpApi"></typeparam>
        /// <param name="client">httpClient</param>
        /// <param name="services">服务提供者</param>
        /// <param name="options">配置选项</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="NotSupportedException"></exception>
        /// <returns></returns>
        public static THttpApi Create <THttpApi>(HttpClient client, IServiceProvider services, HttpApiOptions options)
        {
            if (client == null)
            {
                throw new ArgumentNullException(nameof(client));
            }

            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var context     = new ServiceContext(client, services, options);
            var interceptor = new ActionInterceptor(context);

            return((THttpApi)Create(typeof(THttpApi), interceptor));
        }
 /// <summary>
 /// HttpClient上下文
 /// </summary>
 /// <param name="httpClient">httpClient实例</param>
 /// <param name="serviceProvider">服务提供者</param>
 /// <param name="httpApiOptions">Api配置选项</param>
 /// <exception cref="ArgumentNullException"></exception>
 public HttpClientContext(HttpClient httpClient, IServiceProvider serviceProvider, HttpApiOptions httpApiOptions)
 {
     this.HttpClient      = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
     this.ServiceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider));
     this.HttpApiOptions  = httpApiOptions ?? throw new ArgumentNullException(nameof(httpApiOptions));
 }
Exemple #11
0
 /// <summary>
 /// HttpClient上下文
 /// </summary>
 /// <param name="httpClient">httpClient实例</param>
 /// <param name="serviceProvider">服务提供者</param>
 /// <param name="httpApiOptions">选项</param>
 /// <param name="optionsName">选项名称</param>
 public HttpClientContext(HttpClient httpClient, IServiceProvider serviceProvider, HttpApiOptions httpApiOptions, string optionsName)
 {
     this.HttpClient      = httpClient;
     this.ServiceProvider = serviceProvider;
     this.HttpApiOptions  = httpApiOptions;
     this.OptionsName     = optionsName;
 }
Exemple #12
0
        /// <summary>
        /// 创建THttpApi的代理实例
        /// </summary>
        /// <typeparam name="THttpApi"></typeparam>
        /// <param name="client">httpClient</param>
        /// <param name="services">服务提供者</param>
        /// <param name="options">配置选项</param>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="NotSupportedException"></exception>
        /// <exception cref="ProxyTypeCreateException"></exception>
        /// <returns></returns>
        public static THttpApi Create <THttpApi>(HttpClient client, IServiceProvider services, HttpApiOptions options)
        {
            var context = new ServiceContext(client, services, options);

            return(Create <THttpApi>(new ActionInterceptor(context)));
        }
Exemple #13
0
 /// <summary>
 /// 服务上下文
 /// </summary>
 /// <param name="client"></param>
 /// <param name="services"></param>
 /// <param name="options"></param>
 public ServiceContext(HttpClient client, IServiceProvider services, HttpApiOptions options)
 {
     this.Client   = client;
     this.Services = services;
     this.Options  = options;
 }