public GreetingService(IWebHostEnvironment webHostEnvironment, ILogger <GreetingConfiguration> logger,
                               IOptions <GreetingConfiguration> options)
        {
            _logger = logger;
            var webRootPath   = webHostEnvironment.WebRootPath;
            var greetingsJson = System.IO.File.ReadAllText(webRootPath + "/greetings.json");
            var greetingsData = JsonConvert.DeserializeObject <GreetingData>(greetingsJson);

            Greetings      = greetingsData.Greetings;
            LoginGreetings = greetingsData.LoginGreetings;

            _greetingConfiguration = options.Value;
        }
        //private readonly IOptionsMonitor<GreetingConfiguration> _greetingConfiguration;

        public GreetingService(
            IWebHostEnvironment webHostEnvironment,
            ILogger <GreetingConfiguration> logger,
            IOptionsMonitor <GreetingConfiguration> options)
        {
            var webRootPath   = webHostEnvironment.WebRootPath;
            var greetingsJson = System.IO.File.ReadAllText(webRootPath + "/greetings.json");
            var greetingsData = JsonConvert.DeserializeObject <GreetingData>(greetingsJson);

            Greetings      = greetingsData.Greetings;
            LoginGreetings = greetingsData.LoginGreetings;

            _greetingConfiguration = options.CurrentValue;

            options.OnChange(config =>
            {
                _greetingConfiguration = config;
                logger.LogInformation("The greeting configuration has been updated.");
            });
        }
示例#3
0
        private string GetDesiredLanguage(ChannelUser user)
        {
            GreetingConfiguration greetingConfiguration = configurationManager.LoadConfiguration <GreetingConfiguration>();

            return(greetingConfiguration.RetrieveDesiredLanguage(user.UserId));
        }