/// <summary> /// Add a <see cref="KubeApiClient"/> to the service collection. /// </summary> /// <param name="services"> /// The service collection to configure. /// </param> /// <param name="options"> /// <see cref="KubeClientOptions"/> containing the client configuration to use. /// </param> /// <returns> /// The configured service collection. /// </returns> public static IServiceCollection AddKubeClient(this IServiceCollection services, KubeClientOptions options) { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } options.EnsureValid(); KubeApiClient ResolveWithOptions(IServiceProvider serviceProvider) { KubeClientOptions clientOptions = options.Clone(); if (clientOptions.LoggerFactory == null) { clientOptions.LoggerFactory = serviceProvider.GetService <ILoggerFactory>(); } return(KubeApiClient.Create(options)); } services.AddScoped <KubeApiClient>(ResolveWithOptions); services.AddScoped <IKubeApiClient>(ResolveWithOptions); return(services); }
/// <summary> /// Create a new <see cref="KubeApiClient"/>. /// </summary> /// <param name="httpClient"> /// The underlying HTTP client. /// </param> /// <param name="options"> /// The <see cref="KubeClientOptions"/> used to configure the <see cref="KubeApiClient"/>. /// </param> /// <param name="loggerFactory"> /// The <see cref="ILoggerFactory"/> used to create loggers for client components, or null to use a no-op logger factory. /// </param> KubeApiClient(HttpClient httpClient, KubeClientOptions options, ILoggerFactory loggerFactory) { if (httpClient == null) { throw new ArgumentNullException(nameof(httpClient)); } Http = httpClient; Options = options.Clone(); LoggerFactory = loggerFactory ?? new LoggerFactory(); DefaultNamespace = options.KubeNamespace; }