From d3b84c19c81ba08e29af01e129727e2b6fb59578 Mon Sep 17 00:00:00 2001 From: damianedwards Date: Fri, 18 Dec 2015 13:00:36 -0800 Subject: [PATCH] Tweaked cache key when getting localizer from basName/location: - Cleaned up code a little to make it easier to understand (maybe) - #138 --- .../ResourceManagerStringLocalizerFactory.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.Extensions.Localization/ResourceManagerStringLocalizerFactory.cs b/src/Microsoft.Extensions.Localization/ResourceManagerStringLocalizerFactory.cs index 92a5bab228..905da6727d 100644 --- a/src/Microsoft.Extensions.Localization/ResourceManagerStringLocalizerFactory.cs +++ b/src/Microsoft.Extensions.Localization/ResourceManagerStringLocalizerFactory.cs @@ -66,6 +66,7 @@ namespace Microsoft.Extensions.Localization var typeInfo = resourceSource.GetTypeInfo(); var assembly = typeInfo.Assembly; + // Re-root the base name if a resources path is set var baseName = string.IsNullOrEmpty(_resourcesRelativePath) ? typeInfo.FullName : _applicationEnvironment.ApplicationName + "." + _resourcesRelativePath @@ -93,17 +94,19 @@ namespace Microsoft.Extensions.Localization throw new ArgumentNullException(nameof(baseName)); } - var rootPath = location ?? _applicationEnvironment.ApplicationName; - var assembly = Assembly.Load(new AssemblyName(rootPath)); - baseName = rootPath + "." + _resourcesRelativePath + TrimPrefix(baseName, rootPath + "."); + location = location ?? _applicationEnvironment.ApplicationName; - return _localizerCache.GetOrAdd(baseName, _ => - new ResourceManagerStringLocalizer( + baseName = location + "." + _resourcesRelativePath + TrimPrefix(baseName, location + "."); + + return _localizerCache.GetOrAdd($"B={baseName},L={location}", _ => + { + var assembly = Assembly.Load(new AssemblyName(location)); + return new ResourceManagerStringLocalizer( new ResourceManager(baseName, assembly), assembly, baseName, - _resourceNamesCache) - ); + _resourceNamesCache); + }); } private static string TrimPrefix(string name, string prefix)