/// <summary> /// Adds a I18n Text service to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection. /// </summary> /// <param name="services">The Microsoft.Extensions.DependencyInjection.IServiceCollection to add the service to.</param> public static IServiceCollection AddI18nText(this IServiceCollection services, Action <I18nTextOptions> configure = null) { var options = new I18nTextOptions { GetInitialLanguageAsync = HelperScript.DefaultGetInitialLanguageAsync, PersistCurrentLanguageAsync = HelperScript.DefaultPersistCurrentLanguageAsync, IsWasm = DefaultIsWasm, ConfigureHttpClient = DefaultConfigureHttpClient }; configure?.Invoke(options); if (options.IsWasm() && options.ConfigureHttpClient != null) { services.AddHttpClient(options.HttpClientName, (sp, client) => { options.ConfigureHttpClient.Invoke(sp, client); }); } services.TryAddSingleton(serviceProvider => new I18nTextRepository(serviceProvider, options)); services.TryAddScoped <HelperScript>(); services.TryAddScoped(serviceProvider => { var i18ntext = new I18nText.I18nText(serviceProvider, options); i18ntext.InitializeCurrentLanguage(); return(i18ntext); }); return(services); }
/// <summary> /// Adds a I18n Text service to the specified Microsoft.Extensions.DependencyInjection.IServiceCollection. /// </summary> /// <param name="services">The Microsoft.Extensions.DependencyInjection.IServiceCollection to add the service to.</param> public static IServiceCollection AddI18nText(this IServiceCollection services, Action <I18nTextOptions> configure = null) { services.AddScoped(serviceProvider => { var i18ntext = new I18nText.I18nText(serviceProvider); configure?.Invoke(i18ntext.Options); i18ntext.InitializeCurrentLanguage(); return(i18ntext); }); return(services); }