diff --git a/src/OrchardCore/OrchardCore/Localization/NullStringLocalizerFactory.cs b/src/OrchardCore/OrchardCore/Localization/NullStringLocalizerFactory.cs new file mode 100644 index 00000000000..ecd586a9384 --- /dev/null +++ b/src/OrchardCore/OrchardCore/Localization/NullStringLocalizerFactory.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using Microsoft.Extensions.Localization; + +namespace OrchardCore.Localization +{ + internal class NullStringLocalizerFactory : IStringLocalizerFactory + { + public IStringLocalizer Create(Type resourceSource) => NullStringLocalizer.Instance; + public IStringLocalizer Create(string baseName, string location) => NullStringLocalizer.Instance; + + private class NullStringLocalizer : IStringLocalizer + { + public static NullStringLocalizer Instance { get; } = new NullStringLocalizer(); + + public LocalizedString this[string name] => new LocalizedString(name, name); + + public LocalizedString this[string name, params object[] arguments] + => new LocalizedString(name, string.Format(name, arguments)); + + public IEnumerable GetAllStrings(bool includeParentCultures) + => Enumerable.Empty(); + + public IStringLocalizer WithCulture(CultureInfo culture) => Instance; + } + } +} diff --git a/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs b/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs index a60265bdf92..3e666f23ecc 100644 --- a/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs +++ b/src/OrchardCore/OrchardCore/Modules/Extensions/ServiceCollectionExtensions.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.FileProviders; +using Microsoft.Extensions.Localization; using Microsoft.Extensions.Options; using Microsoft.Net.Http.Headers; using OrchardCore; @@ -17,6 +18,7 @@ using OrchardCore.Environment.Shell; using OrchardCore.Environment.Shell.Configuration; using OrchardCore.Environment.Shell.Descriptor.Models; +using OrchardCore.Localization; using OrchardCore.Modules; namespace Microsoft.Extensions.DependencyInjection @@ -62,6 +64,10 @@ private static void AddDefaultServices(IServiceCollection services) // These services might be moved at a higher level if no components from OrchardCore needs them. services.AddLocalization(); + + // For performance, prevents the 'ResourceManagerStringLocalizer' from being used. + services.AddSingleton(); + services.AddWebEncoders(); // ModularTenantRouterMiddleware which is configured with UseOrchardCore() calls UseRouter() which requires the routing services to be @@ -95,7 +101,7 @@ private static void AddExtensionServices(OrchardCoreBuilder builder) { builder.ApplicationServices.AddSingleton(); builder.ApplicationServices.AddSingleton(); - + builder.ApplicationServices.AddExtensionManagerHost(); builder.ConfigureServices(services =>