示例#1
0
        /// <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);
        }
示例#3
0
        /// <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);
        }