public JsonValueProvider(HttpClient httpClient, IOptions <BlazorI18nJsonConfiguration> configuration) { _configuration = configuration?.Value ?? throw new ArgumentNullException(nameof(IOptions <BlazorI18nJsonConfiguration>)); _httpClient = httpClient ?? throw new ArgumentNullException(nameof(HttpClient)); _httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); }
/// <summary> /// Adds a singleton <see cref="II18n"/> instance to the DI <see cref="IServiceCollection"/> with the specified <see cref="BlazorI18JsonConfiguration"/> /// </summary> public static IServiceCollection AddI18nJsonProvider(this IServiceCollection services, Action <BlazorI18nJsonConfiguration> configure) { if (configure == null) { throw new ArgumentNullException(nameof(configure)); } BlazorI18nJsonConfiguration configuration = new BlazorI18nJsonConfiguration(); configure.Invoke(configuration); services.Configure(configure); services.AddI18n((config) => { config.CurrentLocal = configuration.CurrentLocal; config.DefaultLocal = configuration.DefaultLocal; config.ForceReloadLocal = configuration.ForceReloadLocal; }) .AddSingleton <IValueProvider, JsonValueProvider>(); return(services); }
/// <summary> /// Adds a singleton <see cref="II18n"/> instance to the DI <see cref="IServiceCollection"/> with the specified <see cref="BlazorI18JsonConfiguration"/> /// </summary> public static IServiceCollection AddI18nJsonProvider(this IServiceCollection services, BlazorI18nJsonConfiguration configuration) { if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } if (configuration.LocalsUri == null || configuration.LocalsUri.Count == 0) { throw new ArgumentException($"Locals Uri can't be null and need 1 element."); } return(AddI18nJsonProvider(services, configuration)); }