Пример #1
0
        public static LocalizyOptions From <T>(Action <LocalizyOptions> modifier = null, params ILocalizationStorageProvider[] localizationStorageProviders)
        {
            var options = new LocalizyOptions(new[] { typeof(T).GetTypeInfo().Assembly }, localizationStorageProviders);

            modifier?.Invoke(options);
            return(options);
        }
Пример #2
0
        /// <summary>
        /// Adds services required for application localization.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/> to add the services to.</param>
        /// <param name="localizyOptions">An <see cref="LocalizyOptions"/> object which contains the configuration</param>
        /// <returns>The <see cref="IServiceCollection"/>.</returns>
        public static IServiceCollection AddLocalizy(
            this IServiceCollection services,
            LocalizyOptions localizyOptions)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            var localizationProvider = new LocalizationProviderWithOptions(localizyOptions).WithFilter(localizyOptions.Filter);

            StringToken.LocalizationManager = new LocalizationManagerAdapter(localizationProvider);

            services.Add(new ServiceDescriptor(
                             typeof(ILocalizationProvider),
                             localizationProvider));

            //services.Add(new ServiceDescriptor(
            //    typeof(IStringLocalizer<>),
            //    typeof(LocalizyStringLocalizer<>),
            //    ServiceLifetime.Singleton));

            //services.Add(new ServiceDescriptor(
            //    typeof(IStringLocalizerFactory),
            //    typeof(LocalizyStringLocalizerFactory),
            //    ServiceLifetime.Transient));

            return(services);
        }