Skip to content
This repository has been archived by the owner on Nov 29, 2018. It is now read-only.

Commit

Permalink
Tweaked cache key when getting localizer from basName/location:
Browse files Browse the repository at this point in the history
- Cleaned up code a little to make it easier to understand (maybe)
- #138
  • Loading branch information
DamianEdwards committed Dec 18, 2015
1 parent f55f32f commit 1021dbf
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public IStringLocalizer Create(Type resourceSource)
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
Expand Down Expand Up @@ -93,17 +94,19 @@ public IStringLocalizer Create(string baseName, string location)
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)
Expand Down

0 comments on commit 1021dbf

Please sign in to comment.