/// <summary> /// Add Esquio configuration using store that connect with HTTP API on any Esquio UI deployment. /// </summary> /// <param name="builder">The <see cref="IEsquioBuilder"/> used.</param> /// <param name="setup">The action to configure.</param> /// <returns>A new <see cref="IEsquioBuilder"/> that can be chained for register services.</returns> public static IEsquioBuilder AddHttpStore(this IEsquioBuilder builder, Action <HttpStoreOptions> setup) { const string XAPIKEYHEADERNAME = "X-API-KEY"; var options = new HttpStoreOptions(); setup.Invoke(options); builder.Services .Configure <HttpStoreOptions>(setup => { setup.BaseAddress = options.BaseAddress; setup.ApiKey = options.ApiKey; setup.AbsoluteExpirationRelativeToNow = options.AbsoluteExpirationRelativeToNow; setup.SlidingExpiration = options.SlidingExpiration; setup.Timeout = options.Timeout; setup.CacheEnabled = options.CacheEnabled; }); builder.Services .AddHttpClient(EsquioConstants.ESQUIO, (serviceProvider, httpclient) => { var options = serviceProvider.GetRequiredService <IOptions <HttpStoreOptions> >(); httpclient.BaseAddress = options.Value.BaseAddress; httpclient.DefaultRequestHeaders.Add(XAPIKEYHEADERNAME, options.Value.ApiKey); httpclient.Timeout = options.Value.Timeout; }) .Services .AddDistributedMemoryCache() .AddScoped <IRuntimeFeatureStore, EsquioHttpStore>() .AddSingleton <EsquioHttpStoreDiagnostics>(); return(builder); }
public static IEsquioBuilder AddApplicationInsightProcessor(this IEsquioBuilder builder) { builder.Services.AddApplicationInsightsTelemetryProcessor <EsquioProcessor>(); builder.Services.AddScoped <IFeatureEvaluationObserver, HttpContextItemObserver>(); return(builder); }
/// <summary> /// Add Application Insight observer that include Esquio feature evaluation /// results into all <see cref="Microsoft.ApplicationInsights.Channel.ITelemetry"/> /// entries sent to Application Insight. /// </summary> /// <param name="builder">The <see cref="IEsquioBuilder"/> used.</param> /// <returns>>A new <see cref="IEsquioBuilder"/> that can be chained for register services.</returns> public static IEsquioBuilder AddApplicationInsightProcessor(this IEsquioBuilder builder) { builder.Services .AddApplicationInsightsTelemetry() .AddApplicationInsightsTelemetryProcessor <EsquioAspNetScopedEvaluationSessionProcessor>(); return(builder); }
/// <summary> /// Register a new <see cref="RequestDelegate"/>to be used /// when a requested endpoint does not have candidates availables due a /// disabling evaluation result of any feature. /// </summary> /// <param name="builder">The <see cref="IEsquioBuilder"/> used.</param> /// <param name="requestDelegate">The request delegate to be used.</param> /// <returns>A new <see cref="IEsquioBuilder"/> that can be chained for register services.</returns> /// <remarks> /// You can use <see cref="EndpointFallbackAction"/> to create easily new fallback actions. /// </remarks> public static IEsquioBuilder AddEndpointFallback(this IEsquioBuilder builder, RequestDelegate requestDelegate) { builder.Services.TryAddSingleton(sp => { return(new EndpointFallbackService(requestDelegate)); }); return(builder); }
/// <summary> /// Add Esquio configuration using <see cref="IConfiguration"/>. /// </summary> /// <param name="builder">The <see cref="IEsquioBuilder"/> used.</param> /// <param name="configuration">The <see cref="IConfiguration"/> when the products, features and toggles are configured.</param> /// <param name="key">The configuration section key to use.[Optional] default value is Esquio.</param> /// <returns>A new <see cref="IEsquioBuilder"/> that can be chained for register services.</returns> public static IEsquioBuilder AddConfigurationStore(this IEsquioBuilder builder, IConfiguration configuration, string key = DefaultSectionName) { builder.Services .AddOptions() .Configure <EsquioConfiguration>(configuration.GetSection(key)) .AddScoped <IRuntimeFeatureStore, ConfigurationFeatureStore>(); return(builder); }
/// <summary> /// Register default ASP.NET Core services for Esquio Abstractions. /// </summary> /// <param name="builder">The <see cref="IEsquioBuilder"/> used.</param> /// <returns>A new <see cref="IEsquioBuilder"/> that can be chained for register services.</returns> /// <remarks> /// The registered service are: /// - AspNetCoreUserProviderService that enable get user information from current <see cref="System.Security.Claims.ClaimsPrincipal"/>. /// - AspNetCoreRoleNameProviderService that enable get role information from current <see cref="System.Security.Claims.ClaimsPrincipal"/>. /// - AspNetEnvironmentNameProviderService that enable get enviornment name from current <see cref="Microsoft.AspNetCore.Hosting.IWebHostEnvironment"/>. /// </remarks> public static IEsquioBuilder AddAspNetCoreDefaultServices(this IEsquioBuilder builder) { builder.Services.AddTransient <IUserNameProviderService, AspNetCoreUserNameProviderService>(); builder.Services.AddTransient <IRoleNameProviderService, AspNetCoreRoleNameProviderService>(); builder.Services.AddTransient <IEnvironmentNameProviderService, AspNetEnvironmentNameProviderService>(); builder.Services.AddHttpContextAccessor(); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <MatcherPolicy, FeatureMatcherPolicy>()); return(builder); }
/// <summary> /// Add Esquio configuration using Entity Framework Core. /// </summary> /// <param name="builder">The <see cref="IEsquioBuilder"/> used.</param> /// <param name="configurer">The action to configure default settings for internal Entity Framework Context.[Optional].</param> /// <returns>A new <see cref="IEsquioBuilder"/> that can be chained for register services.</returns> public static IEsquioBuilder AddEntityFrameworkCoreStore(this IEsquioBuilder builder, Action <StoreOptions> configurer = null) { var options = new StoreOptions(); configurer?.Invoke(options); builder.Services.AddDbContext <StoreDbContext>(optionsAction => { options.ConfigureDbContext?.Invoke(optionsAction); }); builder.Services.AddScoped <IRuntimeFeatureStore, EntityFrameworkCoreFeaturesStore>(); return(builder); }
/// <summary> /// Register default ASP.NET Core services for Esquio. /// </summary> /// <param name="builder">The <see cref="IEsquioBuilder"/> used.</param> /// <returns>A new <see cref="IEsquioBuilder"/> that can be chained for register services.</returns> /// <remarks> /// The registered service are: /// - AspNetCoreUserProviderService that enable get user information from current <see cref="System.Security.Claims.ClaimsPrincipal"/>. /// - AspNetCoreRoleNameProviderService that enable get role information from current <see cref="System.Security.Claims.ClaimsPrincipal"/>. /// - AspNetEnvironmentNameProviderService that enable get enviornment name from current <see cref="Microsoft.AspNetCore.Hosting.IWebHostEnvironment"/>. /// </remarks> public static IEsquioBuilder AddAspNetCoreDefaultServices(this IEsquioBuilder builder) { //register diagnostics builder.Services.AddSingleton <EsquioAspNetCoreDiagnostics>(); //register mandatory asp.net core services builder.Services.AddHttpClient(); builder.Services.AddHttpContextAccessor(); builder.Services.AddScoped <IScopedEvaluationHolder, HttpContextScopedEvaluationHolder>(); builder.Services.TryAddEnumerable(ServiceDescriptor.Singleton <MatcherPolicy, FeatureMatcherPolicy>()); //register aspnet core toggles builder.Services.AddTogglesFromAssembly(typeof(EsquioBuilderExtensions).Assembly); return(builder); }