/// <summary> /// Add default Esquio dependencies into the <paramref name="serviceCollection"/>. /// </summary> /// <param name="serviceCollection">The <see cref="IServiceCollection"/>.</param> /// <param name="setup">The action method to configure <see cref="EsquioOptions"/>. Optional, default is null.</param> /// <returns>The <see cref="IEsquioBuilder"/> used to configure Esquio.</returns> public static IEsquioBuilder AddEsquio(this IServiceCollection serviceCollection, Action <EsquioOptions> setup = null) { var options = new EsquioOptions(); setup?.Invoke(options); var builder = new EsquioBuilder(serviceCollection); builder.Services.Configure <EsquioOptions>(opt => { opt.OnErrorBehavior = options.OnErrorBehavior; opt.NotFoundBehavior = options.NotFoundBehavior; opt.DefaultProductName = options.DefaultProductName; opt.ScopedEvaluationEnabled = options.ScopedEvaluationEnabled; opt.DefaultDeploymentName = options.DefaultDeploymentName; }); builder.Services.AddScoped <IFeatureService, DefaultFeatureService>(); builder.Services.AddScoped <IToggleTypeActivator, DefaultToggleTypeActivator>(); //allow to replace this services and not fix the order builder.Services.TryAddScoped <IScopedEvaluationHolder, NoScopedEvaluationHolder>(); builder.Services.TryAddSingleton <IValuePartitioner, DefaultValuePartitioner>(); builder.Services.AddSingleton <EsquioDiagnostics>(); builder.Services.AddTogglesFromAssemblies(options.AssembliesToRegister); return(builder); }
/// <summary> /// Add default Esquio dependencies into the <paramref name="serviceCollection"/>. /// </summary> /// <param name="serviceCollection">The <see cref="IServiceCollection"/>.</param> /// <param name="setup">The action method to configure <see cref="EsquioOptions"/>. Optional, default is null.</param> /// <returns>The <see cref="IEsquioBuilder"/> used to configure Esquio.</returns> public static IEsquioBuilder AddEsquio(this IServiceCollection serviceCollection, Action <EsquioOptions> setup = null) { var options = new EsquioOptions(); setup?.Invoke(options); var builder = new EsquioBuilder(serviceCollection); builder.Services.Configure <EsquioOptions>(opt => { opt.OnErrorBehavior = options.OnErrorBehavior; opt.NotFoundBehavior = options.NotFoundBehavior; opt.DefaultProductName = options.DefaultProductName; }); builder.Services.AddScoped <IFeatureService, DefaultFeatureService>(); builder.Services.AddScoped <IToggleTypeActivator, DefaultToggleTypeActivator>(); builder.Services.AddScoped <IFeatureEvaluationObserver, NoFeatureEvaluationObserver>(); builder.Services.TryAddTransient <IEnvironmentNameProviderService, NoEnvironmentNameProviderService>(); builder.Services.TryAddTransient <IUserNameProviderService, NoUserNameProviderService>(); builder.Services.TryAddTransient <IRoleNameProviderService, NoRoleNameProviderService>(); builder.Services.TryAddSingleton <IValuePartitioner, DefaultValuePartitioner>(); var listener = new DiagnosticListener("Esquio"); builder.Services.AddSingleton <DiagnosticListener>(listener); builder.Services.AddSingleton <DiagnosticSource>(listener); builder.Services.AddSingleton <EsquioDiagnostics>(); builder.Services.AddTogglesFromAssemblies(options.AssembliesToRegister); return(builder); }
public DefaultFeatureService( IRuntimeFeatureStore store, IToggleTypeActivator toggleActivator, IOptions <EsquioOptions> options, EsquioDiagnostics diagnostics) { _featureStore = store ?? throw new ArgumentNullException(nameof(store)); _toggleActivator = toggleActivator ?? throw new ArgumentNullException(nameof(toggleActivator)); _options = options.Value ?? throw new ArgumentNullException(nameof(options)); _diagnostics = diagnostics ?? throw new ArgumentNullException(nameof(diagnostics)); }
public DefaultFeatureService( IRuntimeFeatureStore store, IToggleTypeActivator toggleActivator, IOptions <EsquioOptions> options, ILogger <DefaultFeatureService> logger) { _featureStore = store ?? throw new ArgumentNullException(nameof(store)); _toggleActivator = toggleActivator ?? throw new ArgumentNullException(nameof(toggleActivator)); _options = options.Value ?? throw new ArgumentNullException(nameof(options)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); }
private IFeatureService CreateFeatureService(List <Feature> configuredFeatures, OnErrorBehavior onErrorBehavior = OnErrorBehavior.SetDisabled, NotFoundBehavior notFoundBehavior = NotFoundBehavior.SetDisabled) { var store = new FakeRuntimeStore(configuredFeatures); var activator = new FakeToggleActivator(); var esquioOptions = new EsquioOptions(); esquioOptions.ConfigureOnErrorBehavior(onErrorBehavior); esquioOptions.ConfigureNotFoundBehavior(notFoundBehavior); var options = Options.Create <EsquioOptions>(esquioOptions); var loggerFactory = new LoggerFactory(); var logger = loggerFactory.CreateLogger <DefaultFeatureService>(); return(new DefaultFeatureService(store, activator, options, logger)); }
private IFeatureService CreateFeatureService(List <Feature> configuredFeatures, IScopedEvaluationHolder evaluationSession = null, OnErrorBehavior onErrorBehavior = OnErrorBehavior.SetDisabled, NotFoundBehavior notFoundBehavior = NotFoundBehavior.SetDisabled) { var store = new FakeRuntimeStore(configuredFeatures); var activator = new FakeToggleActivator(); var session = evaluationSession ?? new NoScopedEvaluationHolder(); var esquioOptions = new EsquioOptions(); esquioOptions.ConfigureOnErrorBehavior(onErrorBehavior); esquioOptions.ConfigureNotFoundBehavior(notFoundBehavior); var options = Options.Create <EsquioOptions>(esquioOptions); var loggerFactory = new LoggerFactory(); var esquioDiagnostics = new EsquioDiagnostics(loggerFactory); return(new DefaultFeatureService(store, activator, session, options, esquioDiagnostics)); }
private IFeatureService CreateFeatureService(List <Feature> configuredFeatures, OnErrorBehavior onErrorBehavior = OnErrorBehavior.SetDisabled, NotFoundBehavior notFoundBehavior = NotFoundBehavior.SetDisabled) { var store = new FakeRuntimeStore(configuredFeatures); var activator = new FakeToggleActivator(); var observer = new NoFeatureEvaluationObserver(); var esquioOptions = new EsquioOptions(); esquioOptions.ConfigureOnErrorBehavior(onErrorBehavior); esquioOptions.ConfigureNotFoundBehavior(notFoundBehavior); var options = Options.Create <EsquioOptions>(esquioOptions); var loggerFactory = new LoggerFactory(); var logger = loggerFactory.CreateLogger <global::Esquio.Diagnostics.Esquio>(); var listener = new DiagnosticListener("Esquio"); var esquioDiagnostics = new EsquioDiagnostics(listener, logger); return(new DefaultFeatureService(store, activator, observer, options, esquioDiagnostics)); }
/// <summary> /// Add default Esquio dependencies into the <paramref name="serviceCollection"/>. /// </summary> /// <param name="serviceCollection">The <see cref="IServiceCollection"/>.</param> /// <param name="setup">The action method to configure <see cref="EsquioOptions"/>. Optional, default is null.</param> /// <returns></returns> public static IEsquioBuilder AddEsquio(this IServiceCollection serviceCollection, Action <EsquioOptions> setup = null) { var options = new EsquioOptions(); setup?.Invoke(options); var builder = new EsquioBuilder(serviceCollection); builder.Services.Configure <EsquioOptions>(opt => { opt.OnErrorBehavior = options.OnErrorBehavior; opt.NotFoundBehavior = options.NotFoundBehavior; }); builder.Services.AddScoped <IFeatureService, DefaultFeatureService>(); builder.Services.AddScoped <IToggleTypeActivator, DefaultToggleTypeActivator>(); builder.Services.TryAddTransient <IEnvironmentNameProviderService, NoEnvironmentNameProviderService>(); builder.Services.TryAddTransient <IUserNameProviderService, NoUserNameProviderService>(); builder.Services.TryAddTransient <IRoleNameProviderService, NoRoleNameProviderService>(); builder.Services.AddTogglesFromAssemblies(options.AssembliesToRegister); return(builder); }