Exemplo n.º 1
0
        /// <inheritdoc />
        public LocalizationContext <T> CreateContext <T>()
        {
            var instance = LocalizationDefinitionConvention.CreateLocalizationInstance(typeof(T), s =>
            {
                var fromCache = GetFromCache(s);

                return(fromCache ?? GetNotFoundValue(s));
            });

            return(new LocalizationContext <T>((T)instance));
        }
        public static IServiceCollection AddCulture([NotNull] this IServiceCollection services)
        {
            LocalizationDefinitionConvention.InitializeLocalizationDefinition();

            services.AddMemoryCache()
            .AddOptions();

            services.AddScoped <ICultureContext, CultureContext>();
            services.AddScoped <ICultureContextWriter>(c => c.GetRequiredService <ICultureContext>() as CultureContext);

            services.AddScoped <ILocalizationCache, LocalizationCache>();
            services.AddScoped <ICultureManager, CultureManager>();

            return(services);
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public async ValueTask <LocalizationContext <T> > CreateContextAsync <T>()
        {
            var instance = await LocalizationDefinitionConvention.CreateLocalizationInstanceAsync(typeof(T), key => GetValueAsync(key)).ConfigureAwait(false);

            return(new LocalizationContext <T>((T)instance));
        }