public static IClientConfig GetClientConfiguration(this TulkasOptions tulkasOptions) { return(new ClientConfig { DisableLogging = tulkasOptions.DisableLogging, LogMetrics = tulkasOptions.LogMetrics, MaxRetries = tulkasOptions.MaxRetries }); }
public static IServiceCollection AddTulkasOrderService(this IServiceCollection services, TulkasOptions options, TulkasCredentials credentials) { services.AddHttpClient("Tulkas", client => { client.BaseAddress = new Uri(_baseUri); client.Timeout = TimeSpan.FromSeconds(30); client.DefaultRequestHeaders.Add("User-Agent", "Tulkas.ShopEngine.ApiClient"); }) .ConfigurePrimaryHttpMessageHandler(configure => new HttpClientHandler { AutomaticDecompression = System.Net.DecompressionMethods.GZip | System.Net.DecompressionMethods.Deflate }); services.AddHttpClient("Identity", client => { client.BaseAddress = new Uri(_identityUri); }); services.AddSingleton(options); services.AddSingleton(credentials); services.AddSingleton <IAuthorizationManager, ClientCredentialsManager>(); services.AddSingleton <IRequestManager, DefaultRequestManager>(); services.Configure <TulkasOptions>(o => { o.DisableLogging = options.DisableLogging; o.LogMetrics = options.LogMetrics; o.MaxRetries = options.MaxRetries; }); services.AddSingleton(sp => { return(new TulkasOrderClient(credentials, options.GetClientConfiguration(), sp.GetService <IHttpClientFactory>(), sp.GetService <IAuthorizationManager>(), sp.GetService <IRequestManager>())); }); return(services); }