コード例 #1
0
 private void Changed(PhraseAppOptions newOptions)
 {
     if (options != newOptions)
     {
         options = newOptions;
         //optionsHasChanged = true;
     }
 }
コード例 #2
0
 public PhraseAppLocalization(HttpClient client, IOptionsMonitor <PhraseAppOptions> optionsMonitor, ILogger <PhraseAppLocalization> log, PhraseAppLocalizationCache cache)
 {
     this.client  = client;
     this.options = optionsMonitor.CurrentValue;
     optionsMonitor.OnChange(Changed);
     this.log   = log;
     this.cache = cache;
     this.jsonSerializerOptions = new JsonSerializerOptions()
     {
         PropertyNameCaseInsensitive = true
     };
 }
コード例 #3
0
        public static IServiceCollection AddPhraseApp(this IServiceCollection services, IConfiguration configuration)
        {
            services.AddOptions();
            services.AddOption <PhraseAppOptions, PhraseAppOptionsProvider>();
            services.AddSingleton <PhraseAppLocalizationCache>();// Hey-yo

            var options = new PhraseAppOptions();

            configuration.GetSection(PhraseAppOptionsProvider.Section).Bind(options);
            services.AddHttpClient <ILocalization, PhraseAppLocalization>(client =>
            {
                client.BaseAddress = new Uri(options.Address);
                client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", $"token {options.AccessToken}");
            });

            services.AddHttpClient <PhraseAppLocalization, PhraseAppLocalization>(client =>
            {
                client.BaseAddress = new Uri(options.Address);
                client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", $"token {options.AccessToken}");
            });

            return(services);
        }