diff options
author | Rob Mensching <rob@firegiant.com> | 2017-11-14 23:24:05 -0800 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2017-11-14 23:24:05 -0800 |
commit | 0fa198ed8c6c6fc81e649466879752a99fe37d08 (patch) | |
tree | 7ecaceaf46a87742d0c11500518a9105b21aefad | |
parent | aa6f15ec4998a77622fafe9c510b3b547c595679 (diff) | |
download | wix-0fa198ed8c6c6fc81e649466879752a99fe37d08.tar.gz wix-0fa198ed8c6c6fc81e649466879752a99fe37d08.tar.bz2 wix-0fa198ed8c6c6fc81e649466879752a99fe37d08.zip |
Cache loaded extensions
-rw-r--r-- | src/WixToolset.Core/ExtensionManager.cs | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/src/WixToolset.Core/ExtensionManager.cs b/src/WixToolset.Core/ExtensionManager.cs index 993c21cb..6a9d3b5a 100644 --- a/src/WixToolset.Core/ExtensionManager.cs +++ b/src/WixToolset.Core/ExtensionManager.cs | |||
@@ -14,6 +14,7 @@ namespace WixToolset.Core | |||
14 | internal class ExtensionManager : IExtensionManager | 14 | internal class ExtensionManager : IExtensionManager |
15 | { | 15 | { |
16 | private List<IExtensionFactory> extensionFactories = new List<IExtensionFactory>(); | 16 | private List<IExtensionFactory> extensionFactories = new List<IExtensionFactory>(); |
17 | private Dictionary<Type, List<object>> loadedExtensionsByType = new Dictionary<Type, List<object>>(); | ||
17 | 18 | ||
18 | public void Add(Assembly extensionAssembly) | 19 | public void Add(Assembly extensionAssembly) |
19 | { | 20 | { |
@@ -56,17 +57,22 @@ namespace WixToolset.Core | |||
56 | 57 | ||
57 | public IEnumerable<T> Create<T>() where T : class | 58 | public IEnumerable<T> Create<T>() where T : class |
58 | { | 59 | { |
59 | var extensions = new List<T>(); | 60 | if (!this.loadedExtensionsByType.TryGetValue(typeof(T), out var extensions)) |
60 | |||
61 | foreach (var factory in this.extensionFactories) | ||
62 | { | 61 | { |
63 | if (factory.TryCreateExtension(typeof(T), out var obj) && obj is T extension) | 62 | extensions = new List<object>(); |
63 | |||
64 | foreach (var factory in this.extensionFactories) | ||
64 | { | 65 | { |
65 | extensions.Add(extension); | 66 | if (factory.TryCreateExtension(typeof(T), out var obj) && obj is T extension) |
67 | { | ||
68 | extensions.Add(extension); | ||
69 | } | ||
66 | } | 70 | } |
71 | |||
72 | this.loadedExtensionsByType.Add(typeof(T), extensions); | ||
67 | } | 73 | } |
68 | 74 | ||
69 | return extensions; | 75 | return extensions.Cast<T>().ToList(); |
70 | } | 76 | } |
71 | 77 | ||
72 | private static Assembly ExtensionLoadFrom(string assemblyName) | 78 | private static Assembly ExtensionLoadFrom(string assemblyName) |