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