Exemplo n.º 1
0
        private void RegisterComponentsForNetCore(IConfiguration configuration, IMogglesLoggingService loggingService)
        {
            _mogglesConfigurationManager = new NetCoreMogglesConfigurationManager(configuration);
            MogglesContainer.Register(_mogglesConfigurationManager);

            ConfigureCommonComponents(loggingService);

            var cache = new NetCoreCache();

            _featureToggleService = new MogglesToggleService(cache, _featureToggleProvider, _featureToggleLoggingService, _mogglesConfigurationManager);
            MogglesContainer.Register(_featureToggleService);
        }
        public Task Consume(ConsumeContext <RefreshTogglesCache> context)
        {
            _featureToggleService        = (MogglesToggleService)MogglesContainer.Resolve <MogglesToggleService>();
            _featureToggleLoggingService = (IMogglesLoggingService)MogglesContainer.Resolve <IMogglesLoggingService>();
            _mogglesConfigurationManager = (IMogglesConfigurationManager)MogglesContainer.Resolve <IMogglesConfigurationManager>();

            var msg = context.Message;

            var currentApplication = _mogglesConfigurationManager.GetApplicationName();
            var currentEnvironment = _mogglesConfigurationManager.GetEnvironment();

            if (msg.ApplicationName.ToLowerInvariant() == currentApplication.ToLowerInvariant() &&
                msg.Environment.ToLowerInvariant() == currentEnvironment.ToLowerInvariant())
            {
                _featureToggleLoggingService.TrackEvent($"Handled cache refresh event for {msg.ApplicationName}/{msg.Environment}", currentApplication, currentEnvironment);
                _featureToggleService.CacheFeatureToggles();
            }

            return(Task.FromResult(0));
        }