mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 02:44:52 +08:00
Fix threading issue
Work Item: 17154 --HG-- branch : 1.x
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Autofac;
|
||||
using Autofac.Core;
|
||||
@@ -8,7 +7,7 @@ using Module = Autofac.Module;
|
||||
|
||||
namespace Orchard.Localization {
|
||||
public class LocalizationModule : Module {
|
||||
private readonly IDictionary<string, Localizer> _localizerCache;
|
||||
private readonly ConcurrentDictionary<string, Localizer> _localizerCache;
|
||||
|
||||
public LocalizationModule() {
|
||||
_localizerCache = new ConcurrentDictionary<string, Localizer>();
|
||||
@@ -26,14 +25,8 @@ namespace Orchard.Localization {
|
||||
var scope = registration.Activator.LimitType.FullName;
|
||||
|
||||
registration.Activated += (sender, e) => {
|
||||
if (_localizerCache.ContainsKey(scope)) {
|
||||
userProperty.SetValue(e.Instance, _localizerCache[scope], null);
|
||||
}
|
||||
else {
|
||||
var localizer = LocalizationUtilities.Resolve(e.Context, scope);
|
||||
_localizerCache.Add(scope, localizer);
|
||||
userProperty.SetValue(e.Instance, localizer, null);
|
||||
}
|
||||
var localizer = _localizerCache.GetOrAdd(scope, key => LocalizationUtilities.Resolve(e.Context, scope));
|
||||
userProperty.SetValue(e.Instance, localizer, null);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@@ -11,7 +11,7 @@ using Module = Autofac.Module;
|
||||
namespace Orchard.Logging {
|
||||
|
||||
public class LoggingModule : Module {
|
||||
private readonly IDictionary<string, ILogger> _loggerCache;
|
||||
private readonly ConcurrentDictionary<string, ILogger> _loggerCache;
|
||||
|
||||
public LoggingModule() {
|
||||
_loggerCache = new ConcurrentDictionary<string, ILogger>();
|
||||
@@ -63,14 +63,8 @@ namespace Orchard.Logging {
|
||||
|
||||
yield return (ctx, instance) => {
|
||||
string component = componentType.ToString();
|
||||
if (_loggerCache.ContainsKey(component)) {
|
||||
propertyInfo.SetValue(instance, _loggerCache[component], null);
|
||||
}
|
||||
else {
|
||||
var propertyValue = ctx.Resolve<ILogger>(new TypedParameter(typeof(Type), componentType));
|
||||
_loggerCache.Add(component, propertyValue);
|
||||
propertyInfo.SetValue(instance, propertyValue, null);
|
||||
}
|
||||
var logger = _loggerCache.GetOrAdd(component, key => ctx.Resolve<ILogger>(new TypedParameter(typeof(Type), componentType)));
|
||||
propertyInfo.SetValue(instance, logger, null);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user