diff options
author | Rob Mensching <rob@firegiant.com> | 2018-10-24 21:04:19 -0700 |
---|---|---|
committer | Rob Mensching <rob@robmensching.com> | 2018-10-24 21:17:34 -0700 |
commit | f195604266cb2b675d31c21df343e1f2ac8bdb0c (patch) | |
tree | 219c542f50584a5aacfb94f305c6b42beaa87cd5 /src/WixToolset.Core | |
parent | a5c63c90a02665267c11c8bf2c653fd6db8d0107 (diff) | |
download | wix-f195604266cb2b675d31c21df343e1f2ac8bdb0c.tar.gz wix-f195604266cb2b675d31c21df343e1f2ac8bdb0c.tar.bz2 wix-f195604266cb2b675d31c21df343e1f2ac8bdb0c.zip |
Support passing IServiceProvider to IExtensionFactory's
Diffstat (limited to 'src/WixToolset.Core')
-rw-r--r-- | src/WixToolset.Core/ExtensibilityServices/ExtensionManager.cs | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/WixToolset.Core/ExtensibilityServices/ExtensionManager.cs b/src/WixToolset.Core/ExtensibilityServices/ExtensionManager.cs index 5714701a..2ecf85ae 100644 --- a/src/WixToolset.Core/ExtensibilityServices/ExtensionManager.cs +++ b/src/WixToolset.Core/ExtensibilityServices/ExtensionManager.cs | |||
@@ -16,14 +16,32 @@ namespace WixToolset.Core.ExtensibilityServices | |||
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 | private Dictionary<Type, List<object>> loadedExtensionsByType = new Dictionary<Type, List<object>>(); |
18 | 18 | ||
19 | public ExtensionManager(IServiceProvider serviceProvider) | ||
20 | { | ||
21 | this.ServiceProvider = serviceProvider; | ||
22 | } | ||
23 | |||
24 | private IServiceProvider ServiceProvider { get; } | ||
25 | |||
19 | public void Add(Assembly extensionAssembly) | 26 | public void Add(Assembly extensionAssembly) |
20 | { | 27 | { |
21 | var types = extensionAssembly.GetTypes().Where(t => !t.IsAbstract && !t.IsInterface && typeof(IExtensionFactory).IsAssignableFrom(t)); | 28 | var types = extensionAssembly.GetTypes().Where(t => !t.IsAbstract && !t.IsInterface && typeof(IExtensionFactory).IsAssignableFrom(t)); |
22 | var factories = types.Select(t => (IExtensionFactory)Activator.CreateInstance(t)).ToList(); | 29 | var factories = types.Select(this.CreateExtensionFactory).ToList(); |
23 | 30 | ||
24 | this.extensionFactories.AddRange(factories); | 31 | this.extensionFactories.AddRange(factories); |
25 | } | 32 | } |
26 | 33 | ||
34 | private IExtensionFactory CreateExtensionFactory(Type type) | ||
35 | { | ||
36 | var constructor = type.GetConstructor(new[] { typeof(IServiceProvider) }); | ||
37 | if (constructor != null) | ||
38 | { | ||
39 | return (IExtensionFactory)constructor.Invoke(new[] { this.ServiceProvider }); | ||
40 | } | ||
41 | |||
42 | return (IExtensionFactory)Activator.CreateInstance(type); | ||
43 | } | ||
44 | |||
27 | public void Load(string extensionPath) | 45 | public void Load(string extensionPath) |
28 | { | 46 | { |
29 | Assembly assembly; | 47 | Assembly assembly; |