mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
PERF: Fixing 16889 IText pooling
--HG-- branch : perf
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
namespace Orchard.Localization {
|
||||
public interface IText {
|
||||
public interface IText : ISingletonDependency {
|
||||
LocalizedString Get(string textHint, params object[] args);
|
||||
}
|
||||
}
|
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Autofac;
|
||||
using Autofac.Core;
|
||||
@@ -6,6 +7,11 @@ using Module = Autofac.Module;
|
||||
|
||||
namespace Orchard.Localization {
|
||||
public class LocalizationModule : Module {
|
||||
private readonly IDictionary<string, Localizer> _localizerCache;
|
||||
|
||||
public LocalizationModule() {
|
||||
_localizerCache = new Dictionary<string, Localizer>();
|
||||
}
|
||||
|
||||
protected override void Load(ContainerBuilder builder) {
|
||||
builder.RegisterType<Text>().As<IText>().InstancePerDependency();
|
||||
@@ -19,8 +25,14 @@ namespace Orchard.Localization {
|
||||
var scope = registration.Activator.LimitType.FullName;
|
||||
|
||||
registration.Activated += (sender, e) => {
|
||||
var localizer = LocalizationUtilities.Resolve(e.Context, scope);
|
||||
userProperty.SetValue(e.Instance, localizer, null);
|
||||
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);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user