コード例 #1
0
 public TodoController(ILogger <TodoController> logger,
                       ITodoServiceAsyncContext serviceContext,
                       IConfiguration configuration,
                       IWebHostEnvironment webHostEnvironment,
                       IFeatureFlags featureFlags)
 {
     _configuration     = configuration;
     _logger            = logger;
     _serviceAgent      = new TodoServiceAsyncAgent(serviceContext);
     _version           = configuration["TodoControllerVersion"];
     _environment       = webHostEnvironment.EnvironmentName;
     _featureFlagsInUse = featureFlags;
 }
コード例 #2
0
 public FeatureFlags(IConfiguration configuration, ITodoServiceAsyncContext context)
 {
     _featureFlags = FeatureFlagsFactory.GetFeatureFlagsInUse(configuration, context);
 }
コード例 #3
0
        public static IEnumerable <FeatureFlagViewModel> GetFeatureFlagsInUse(IConfiguration configuration, ITodoServiceAsyncContext context)
        {
            if (null == LaunchDarklyCredentials)
            {
                InitializeFeatureFlagConfiguration(configuration);
            }

            // We can only activate feature flags when all pre-req features are active
            // If pre-req flags is empty, the flag is only implemented inside this servive

            var featurFlagsInUse = CloneFlags(_webuiSupportedFeatureFlags);
            IEnumerable <FeatureFlagViewModel> apiSupportedFeatureFlags = GetServiceSupportedFeatureFlags(context);

            //Validate pre req
            foreach (var apiFlag in featurFlagsInUse)
            {
                foreach (var dbFlag in apiFlag.PreReqKeys)
                {
                    var preReq = apiSupportedFeatureFlags.SingleOrDefault(f => f.Key == dbFlag.Key);
                    if (preReq != null)
                    {
                        dbFlag.State = preReq.State;
                    }
                }
            }

            if (LaunchDarklyCredentials.LdClient != null)
            {
                foreach (var featureFlag in featurFlagsInUse)
                {
                    featureFlag.State = LaunchDarklyCredentials.LdClient.BoolVariation(featureFlag.Key, LaunchDarklyCredentials.LdUser, false);
                }
            }
            return(featurFlagsInUse);
        }
コード例 #4
0
        private static IEnumerable <FeatureFlagViewModel> GetServiceSupportedFeatureFlags(ITodoServiceAsyncContext serviceAgent)
        {
            var task  = Task.Run(() => serviceAgent.SupportedFeatureFlags());
            var flags = (IEnumerable <Service.Models.FeatureFlagDTO>)task.GetType().GetProperty("Result").GetValue(task);
            IEnumerable <FeatureFlagViewModel> serviceSupportedFeatureFlags = flags.ToList().ConvertAll(new Converter <Service.Models.FeatureFlagDTO, FeatureFlagViewModel>(ViewModelFeatureFlagMapper.Map));

            return(serviceSupportedFeatureFlags);
        }
コード例 #5
0
 public TodoServiceAsyncAgent(ITodoServiceAsyncContext context)
 {
     Context = context;
 }