|
1 | | -using System; |
| 1 | +using Castle.DynamicProxy; |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
2 | 4 | using System.Net.Http; |
3 | | -using Castle.DynamicProxy; |
4 | | -using System.Collections.Concurrent; |
| 5 | +using System.Text; |
5 | 6 |
|
6 | 7 | namespace DotNetCoreRpc.Client |
7 | 8 | { |
8 | | - public class RpcClient |
| 9 | + internal class RpcClient |
9 | 10 | { |
10 | | - private readonly ProxyGenerator _proxyGenerator; |
11 | | - private readonly IHttpClientFactory _httpClientFactory; |
| 11 | + private HttpClient _httpClient; |
| 12 | + private ProxyGenerator _proxyGenerator; |
12 | 13 |
|
13 | | - public RpcClient(ProxyGenerator proxyGenerator, IHttpClientFactory httpClientFactory) |
| 14 | + public RpcClient(HttpClient httpClient, ProxyGenerator proxyGenerator) |
14 | 15 | { |
| 16 | + _httpClient = httpClient; |
| 17 | + _httpClient.DefaultRequestHeaders.Add("req-source", "dncrpc"); |
15 | 18 | _proxyGenerator = proxyGenerator; |
16 | | - _httpClientFactory = httpClientFactory; |
17 | 19 | } |
18 | 20 |
|
19 | | - public T CreateClient<T>(string serviceName) where T : class |
| 21 | + internal T CreateClient<T>() where T : class |
20 | 22 | { |
21 | | - return CreateClient<T>(_httpClientFactory.CreateClient(serviceName)); |
22 | | - } |
23 | | - |
24 | | - public T CreateClient<T>(HttpClient httpClient) where T : class |
25 | | - { |
26 | | - httpClient.DefaultRequestHeaders.Add("req-source", "dncrpc"); |
27 | | - HttpRequestInterceptor httpRequestInterceptor = new HttpRequestInterceptor(httpClient); |
| 23 | + HttpRequestInterceptor httpRequestInterceptor = new HttpRequestInterceptor(_httpClient); |
28 | 24 | return _proxyGenerator.CreateInterfaceProxyWithoutTarget<T>(httpRequestInterceptor); |
29 | 25 | } |
30 | 26 | } |
|
0 commit comments