Exemplo n.º 1
0
        internal static void AddTierBasedServices(IServiceCollection services, IConfiguration configuration,
                                                  SupportedTier supportedTier)
        {
            switch (supportedTier)
            {
            case SupportedTier.App:
                services.AddAppDbContext(configuration);
                services.RegisterAppAutoMapper();
                services.RegisterAppRepositories();
                services.RegisterAppServices();
                services.TryAddScoped <IFeatureDefinitionProvider, EfCoreFeatureDefinitionProvider>();
                break;

            case SupportedTier.Web:
                services.Configure <ApiOptions>(options =>
                                                options.FeatureManagementUri = configuration["FeatureManagement.Api.Endpoint"]);
                services.TryAddScoped <IFeatureDefinitionProvider, ApiFeatureDefinitionProvider>();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(supportedTier), supportedTier, null);
            }
        }
Exemplo n.º 2
0
        internal static IFeatureManagementBuilder AddFeatureManagement(this IServiceCollection services,
                                                                       IConfiguration configuration, SupportedTier supportedTier)
        {
            #region Parameter Validation

            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            #endregion

            services.AddLogging();

            services.AddSingleton <ITargetingContextAccessor, HttpContextTargetingContextAccessor>();

            AddTierBasedServices(services, configuration, supportedTier);

            services.TryAddScoped <IFeatureManager, FeatureManager>();

            services.TryAddScoped <ISessionManager, EmptySessionManager>();

            services.AddScoped <IFeatureManagerSnapshot, FeatureManagerSnapshot>();

            return(new FeatureManagementBuilder(services));
        }