public static IUnleashServiceCollection WithMemoryToggleCollectionCache(this IUnleashServiceCollection serviceCollection, Action <MemoryToggleCollectionCacheSettings> settingsConfigurator = null) { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } var settings = new MemoryToggleCollectionCacheSettings(); if (serviceCollection.UnleashConfiguration != null) { var section = serviceCollection.UnleashConfiguration.GetSection("Caching:Memory"); section.Bind(settings); } settingsConfigurator?.Invoke(settings); SettingsValidator.Validate(settings); serviceCollection.AddSingleton(settings); serviceCollection.AddMemoryCache(); serviceCollection.WithToggleCollectionCache <MemoryToggleCollectionCache>(); return(serviceCollection); }
public static IUnleashServiceCollection WithNewtonsoftJsonSerializer(this IUnleashServiceCollection serviceCollection, Action <NewtonsoftJsonSerializerSettings> settingsConfigurator = null) { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } var settings = new NewtonsoftJsonSerializerSettings(); if (serviceCollection.UnleashConfiguration != null) { var section = serviceCollection.UnleashConfiguration.GetSection("Serialization:NewtonsoftJson"); section.Bind(settings); } settingsConfigurator?.Invoke(settings); SettingsValidator.Validate(settings); serviceCollection.AddSingleton(settings); serviceCollection.WithJsonSerializer <NewtonsoftJsonSerializer>(); return(serviceCollection); }
public static IUnleashServiceCollection WithAdminHttpClientFactory(this IUnleashServiceCollection serviceCollection, Action <IHttpClientBuilder> httpClientConfigurator = null) { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } var httpClientBuilder = serviceCollection.AddHttpClient <IUnleashAdminApiClient, UnleashAdminApiClient>() .ConfigureHttpClient( (sp, httpClient) => { var settings = sp.GetRequiredService <UnleashSettings>(); httpClient.BaseAddress = settings.UnleashApi; httpClient.DefaultRequestHeaders.ConnectionClose = false; httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Accept", "application/json"); httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json"); httpClient.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true }; }); serviceCollection.AddSingleton <IUnleashApiClientFactory, HttpClientFactoryApiClientFactory>(); httpClientConfigurator?.Invoke(httpClientBuilder); return(serviceCollection); }
public static IUnleashServiceCollection WithScheduledTaskManager <TScheduledTaskManager>(this IUnleashServiceCollection serviceCollection, Func <IServiceProvider, TScheduledTaskManager> scheduledTaskManagerFactory) where TScheduledTaskManager : class, IUnleashScheduledTaskManager { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } serviceCollection.AddSingleton <IUnleashScheduledTaskManager>(scheduledTaskManagerFactory); return(serviceCollection); }
public static IUnleashServiceCollection WithStrategy <TStrategy>(this IUnleashServiceCollection serviceCollection, Func <IServiceProvider, TStrategy> strategyFactory) where TStrategy : class, IStrategy { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } serviceCollection.AddSingleton <IStrategy>(strategyFactory); return(serviceCollection); }
public static IUnleashServiceCollection WithJsonSerializer <TJsonSerializer>(this IUnleashServiceCollection serviceCollection, Func <IServiceProvider, TJsonSerializer> jsonSerializerFactory) where TJsonSerializer : class, IJsonSerializer { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } serviceCollection.AddSingleton <IJsonSerializer>(jsonSerializerFactory); return(serviceCollection); }
public static IUnleashServiceCollection WithToggleCollectionCache <TToggleCollectionCache>(this IUnleashServiceCollection serviceCollection, Func <IServiceProvider, TToggleCollectionCache> toggleCollectionCacheFactory) where TToggleCollectionCache : class, IToggleCollectionCache { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } serviceCollection.AddSingleton <IToggleCollectionCache, TToggleCollectionCache>(toggleCollectionCacheFactory); return(serviceCollection); }
public static IUnleashServiceCollection WithHostControlledLifetime(this IUnleashServiceCollection serviceCollection) { if (serviceCollection == null) { throw new ArgumentNullException(nameof(serviceCollection)); } serviceCollection.AddSingleton <IHostedService, HostControlledLifetimeService>(); return(serviceCollection); }