Tweaked cache key when getting localizer from basName/location:
- Cleaned up code a little to make it easier to understand (maybe) - #138
This commit is contained in:
parent
0b9b99e617
commit
d3b84c19c8
|
|
@ -66,6 +66,7 @@ namespace Microsoft.Extensions.Localization
|
||||||
var typeInfo = resourceSource.GetTypeInfo();
|
var typeInfo = resourceSource.GetTypeInfo();
|
||||||
var assembly = typeInfo.Assembly;
|
var assembly = typeInfo.Assembly;
|
||||||
|
|
||||||
|
// Re-root the base name if a resources path is set
|
||||||
var baseName = string.IsNullOrEmpty(_resourcesRelativePath)
|
var baseName = string.IsNullOrEmpty(_resourcesRelativePath)
|
||||||
? typeInfo.FullName
|
? typeInfo.FullName
|
||||||
: _applicationEnvironment.ApplicationName + "." + _resourcesRelativePath
|
: _applicationEnvironment.ApplicationName + "." + _resourcesRelativePath
|
||||||
|
|
@ -93,17 +94,19 @@ namespace Microsoft.Extensions.Localization
|
||||||
throw new ArgumentNullException(nameof(baseName));
|
throw new ArgumentNullException(nameof(baseName));
|
||||||
}
|
}
|
||||||
|
|
||||||
var rootPath = location ?? _applicationEnvironment.ApplicationName;
|
location = location ?? _applicationEnvironment.ApplicationName;
|
||||||
var assembly = Assembly.Load(new AssemblyName(rootPath));
|
|
||||||
baseName = rootPath + "." + _resourcesRelativePath + TrimPrefix(baseName, rootPath + ".");
|
|
||||||
|
|
||||||
return _localizerCache.GetOrAdd(baseName, _ =>
|
baseName = location + "." + _resourcesRelativePath + TrimPrefix(baseName, location + ".");
|
||||||
new ResourceManagerStringLocalizer(
|
|
||||||
|
return _localizerCache.GetOrAdd($"B={baseName},L={location}", _ =>
|
||||||
|
{
|
||||||
|
var assembly = Assembly.Load(new AssemblyName(location));
|
||||||
|
return new ResourceManagerStringLocalizer(
|
||||||
new ResourceManager(baseName, assembly),
|
new ResourceManager(baseName, assembly),
|
||||||
assembly,
|
assembly,
|
||||||
baseName,
|
baseName,
|
||||||
_resourceNamesCache)
|
_resourceNamesCache);
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string TrimPrefix(string name, string prefix)
|
private static string TrimPrefix(string name, string prefix)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue