private static void ConfigureHttpClient(IServiceProvider serviceProvider, HttpClient client, ServiceSettings serviceSettings, Action <IServiceProvider, HttpClient> clientCreatedAction)
        {
            client.BaseAddress = new Uri(serviceSettings.Url);

            IRequestHeaderHelper requestHeaderHelper = serviceProvider.GetService <IRequestHeaderHelper>();

            requestHeaderHelper.InitializeHeaders(client, serviceSettings).Wait();

            // invoke event
            clientCreatedAction?.Invoke(serviceProvider, client);
        }
        protected AgentBase(HttpClient client, IServiceProvider serviceProvider, IOptions <ServiceAgentSettings> options)
        {
            if (options.Value == null)
            {
                throw new ArgumentNullException(nameof(ServiceAgentSettings), $"{nameof(ServiceAgentSettings)} cannot be null.");
            }

            _client          = client ?? throw new ArgumentNullException(nameof(client), $"Http client cannot be null.");
            _serviceProvider = serviceProvider ?? throw new ArgumentNullException(nameof(serviceProvider), $"Service provider cannot be null.");

            _settings = GetServiceSettings(options.Value);

            _requestHeaderHelper = _serviceProvider.GetService <IRequestHeaderHelper>();
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HttpClientFactory"/> class.
 /// </summary>
 /// <param name="requestHeaderHelper"></param>
 public HttpClientFactory(IRequestHeaderHelper requestHeaderHelper)
 {
     this.requestHeaderHelper = requestHeaderHelper;
 }