Introduce IExtensionFactory as mechanism to create extensions
Rob Mensching committed
Nov 11, 2017 at 12:40 UTC
3f6e936c5e9d7a9df7e3e0ed1bc17001c53db5b3
2 files changed
+43
-2
src/WixToolset.Extensibility/IExtensionFactory.cs
new
+17
@@ -0,0 +1,17 @@
1
+// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information.
2
+
3
+namespace WixToolset.Extensibility
4
+{
5
+ using System;
6
+
7
+ public interface IExtensionFactory
8
+ {
9
+ /// <summary>
10
+ /// Request to create an extension of the specified type.
11
+ /// </summary>
12
+ /// <param name="extensionType">Extension type to create.</param>
13
+ /// <param name="extension">Extension created.</param>
14
+ /// <returns>True if extension was created; otherwise false.</returns>
15
+ bool TryCreateExtension(Type extensionType, out object extension);
16
+ }
17
+}
src/WixToolset.Extensibility/Services/IExtensionManager.cs
+26
-2
@@ -7,10 +7,34 @@ namespace WixToolset.Extensibility.Services
7
8
public interface IExtensionManager
9
{
10
- Assembly Add(Assembly assembly);
10
+ /// <summary>
11
+ /// Adds an extension assembly directly to the manager.
12
+ /// </summary>
13
+ /// <param name="extensionAssembly">Extension assembly.</param>
14
+ void Add(Assembly extensionAssembly);
15
12
- Assembly Load(string extension);
16
+ /// <summary>
17
+ /// Loads an extension assembly from a type description string.
18
+ /// </summary>
19
+ /// <param name="extension">The assembly type description string.</param>
20
+ /// <returns>The loaded assembly. This assembly can be ignored since the extension manager maintains the list of loaded assemblies internally.</returns>
21
+ /// <remarks>
22
+ /// <paramref name="extension"/> can be in several different forms:
23
+ /// <list type="number">
24
+ /// <item><term>AssemblyName (MyAssembly, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b17a5c561934e089)</term></item>
25
+ /// <item><term>Absolute path to an assembly (C:\MyExtensions\ExtensionAssembly.dll)</term></item>
26
+ /// <item><term>Filename of an assembly in the application directory (ExtensionAssembly.dll)</term></item>
27
+ /// <item><term>Relative path to an assembly (..\..\MyExtensions\ExtensionAssembly.dll)</term></item>
28
+ /// </list>
29
+ /// </remarks>
30
+ void Load(string extensionPath);
31
32
+
33
+ /// <summary>
34
+ /// Creates extension of specified type from factories loaded into the extension manager.
35
+ /// </summary>
36
+ /// <typeparam name="T">Type of extension to create.</typeparam>
37
+ /// <returns>Extensions created of the specified type.</returns>
38
IEnumerable<T> Create<T>() where T : class;
39
}
40
}