aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2017-10-17 02:47:44 -0700
committerRob Mensching <rob@firegiant.com>2017-10-18 13:31:55 -0700
commitc08fd0aefeea1628fe93c818ca4dde63fd6ac2e1 (patch)
treeac63402f6bad7f3a5bc20b088914145d9bf8635b /src/WixToolset.Core
parent6dd045318f7ee405e92e76d311ad1424c20157c1 (diff)
downloadwix-c08fd0aefeea1628fe93c818ca4dde63fd6ac2e1.tar.gz
wix-c08fd0aefeea1628fe93c818ca4dde63fd6ac2e1.tar.bz2
wix-c08fd0aefeea1628fe93c818ca4dde63fd6ac2e1.zip
Introduce WixToolsetServiceProvider
Using a service provider allows all of WixToolset.Core's internal functionality to be abstracted behind interfaces in WixToolset.Extensibility. The service provide can also control what interfaces are singletons.
Diffstat (limited to 'src/WixToolset.Core')
-rw-r--r--src/WixToolset.Core/BindContext.cs9
-rw-r--r--src/WixToolset.Core/Binder.cs5
-rw-r--r--src/WixToolset.Core/CommandLine/BuildCommand.cs10
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLine.cs64
-rw-r--r--src/WixToolset.Core/CommandLine/CommandLineContext.cs26
-rw-r--r--src/WixToolset.Core/CommandLine/CompileCommand.cs3
-rw-r--r--src/WixToolset.Core/CommandLine/HelpCommand.cs1
-rw-r--r--src/WixToolset.Core/CommandLine/ICommandLineCommand.cs9
-rw-r--r--src/WixToolset.Core/CommandLine/VersionCommand.cs5
-rw-r--r--src/WixToolset.Core/ExtensionManager.cs18
-rw-r--r--src/WixToolset.Core/IncribeContext.cs8
-rw-r--r--src/WixToolset.Core/WixToolsetServiceProvider.cs47
12 files changed, 149 insertions, 56 deletions
diff --git a/src/WixToolset.Core/BindContext.cs b/src/WixToolset.Core/BindContext.cs
index 499f3245..7b1a1877 100644
--- a/src/WixToolset.Core/BindContext.cs
+++ b/src/WixToolset.Core/BindContext.cs
@@ -2,12 +2,21 @@
2 2
3namespace WixToolset.Core 3namespace WixToolset.Core
4{ 4{
5 using System;
5 using System.Collections.Generic; 6 using System.Collections.Generic;
6 using WixToolset.Data; 7 using WixToolset.Data;
7 using WixToolset.Extensibility; 8 using WixToolset.Extensibility;
9 using WixToolset.Extensibility.Services;
8 10
9 public class BindContext : IBindContext 11 public class BindContext : IBindContext
10 { 12 {
13 internal BindContext(IServiceProvider serviceProvider)
14 {
15 this.ServiceProvider = serviceProvider;
16 }
17
18 public IServiceProvider ServiceProvider { get; }
19
11 public Messaging Messaging { get; set; } 20 public Messaging Messaging { get; set; }
12 21
13 public IEnumerable<BindPath> BindPaths { get; set; } 22 public IEnumerable<BindPath> BindPaths { get; set; }
diff --git a/src/WixToolset.Core/Binder.cs b/src/WixToolset.Core/Binder.cs
index 43c15634..34bf0dee 100644
--- a/src/WixToolset.Core/Binder.cs
+++ b/src/WixToolset.Core/Binder.cs
@@ -16,6 +16,7 @@ namespace WixToolset.Core
16 using WixToolset.Data.Bind; 16 using WixToolset.Data.Bind;
17 using WixToolset.Data.Rows; 17 using WixToolset.Data.Rows;
18 using WixToolset.Extensibility; 18 using WixToolset.Extensibility;
19 using WixToolset.Extensibility.Services;
19 20
20 /// <summary> 21 /// <summary>
21 /// Binder of the WiX toolset. 22 /// Binder of the WiX toolset.
@@ -42,14 +43,14 @@ namespace WixToolset.Core
42 //this.SuppressIces = new List<string>(); 43 //this.SuppressIces = new List<string>();
43 } 44 }
44 45
45 public Binder(BindContext context) 46 public Binder(IBindContext context)
46 { 47 {
47 this.Context = context; 48 this.Context = context;
48 49
49 this.TableDefinitions = WindowsInstallerStandard.GetTableDefinitions(); 50 this.TableDefinitions = WindowsInstallerStandard.GetTableDefinitions();
50 } 51 }
51 52
52 private BindContext Context { get; } 53 private IBindContext Context { get; }
53 54
54 private TableDefinitionCollection TableDefinitions { get; } 55 private TableDefinitionCollection TableDefinitions { get; }
55 56
diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs
index b3909451..4a1fc1ed 100644
--- a/src/WixToolset.Core/CommandLine/BuildCommand.cs
+++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs
@@ -9,11 +9,13 @@ namespace WixToolset.Core
9 using WixToolset.Data; 9 using WixToolset.Data;
10 using WixToolset.Data.Rows; 10 using WixToolset.Data.Rows;
11 using WixToolset.Extensibility; 11 using WixToolset.Extensibility;
12 using WixToolset.Extensibility.Services;
12 13
13 internal class BuildCommand : ICommandLineCommand 14 internal class BuildCommand : ICommandLineCommand
14 { 15 {
15 public BuildCommand(ExtensionManager extensions, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables, IEnumerable<string> locFiles, IEnumerable<string> libraryFiles, string outputPath, OutputType outputType, string cabCachePath, IEnumerable<string> cultures, bool bindFiles, IEnumerable<BindPath> bindPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile, string wixProjectFile) 16 public BuildCommand(IServiceProvider serviceProvider, IExtensionManager extensions, IEnumerable<SourceFile> sources, IDictionary<string, string> preprocessorVariables, IEnumerable<string> locFiles, IEnumerable<string> libraryFiles, string outputPath, OutputType outputType, string cabCachePath, IEnumerable<string> cultures, bool bindFiles, IEnumerable<BindPath> bindPaths, string intermediateFolder, string contentsFile, string outputsFile, string builtOutputsFile, string wixProjectFile)
16 { 17 {
18 this.ServiceProvider = serviceProvider;
17 this.ExtensionManager = extensions; 19 this.ExtensionManager = extensions;
18 this.LocFiles = locFiles; 20 this.LocFiles = locFiles;
19 this.LibraryFiles = libraryFiles; 21 this.LibraryFiles = libraryFiles;
@@ -34,7 +36,9 @@ namespace WixToolset.Core
34 this.WixProjectFile = wixProjectFile; 36 this.WixProjectFile = wixProjectFile;
35 } 37 }
36 38
37 public ExtensionManager ExtensionManager { get; } 39 public IServiceProvider ServiceProvider { get; }
40
41 public IExtensionManager ExtensionManager { get; }
38 42
39 public IEnumerable<string> LocFiles { get; } 43 public IEnumerable<string> LocFiles { get; }
40 44
@@ -173,7 +177,7 @@ namespace WixToolset.Core
173 intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); 177 intermediateFolder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
174 } 178 }
175 179
176 var context = new BindContext(); 180 var context = this.ServiceProvider.GetService<IBindContext>();
177 context.Messaging = Messaging.Instance; 181 context.Messaging = Messaging.Instance;
178 context.ExtensionManager = this.ExtensionManager; 182 context.ExtensionManager = this.ExtensionManager;
179 context.BindPaths = this.BindPaths ?? Array.Empty<BindPath>(); 183 context.BindPaths = this.BindPaths ?? Array.Empty<BindPath>();
diff --git a/src/WixToolset.Core/CommandLine/CommandLine.cs b/src/WixToolset.Core/CommandLine/CommandLine.cs
index 2f203ecb..b0594348 100644
--- a/src/WixToolset.Core/CommandLine/CommandLine.cs
+++ b/src/WixToolset.Core/CommandLine/CommandLine.cs
@@ -6,11 +6,11 @@ namespace WixToolset.Core
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.IO; 7 using System.IO;
8 using System.Linq; 8 using System.Linq;
9 using System.Reflection;
10 using System.Text; 9 using System.Text;
11 using System.Text.RegularExpressions; 10 using System.Text.RegularExpressions;
12 using WixToolset.Data; 11 using WixToolset.Data;
13 using WixToolset.Extensibility; 12 using WixToolset.Extensibility;
13 using WixToolset.Extensibility.Services;
14 14
15 internal enum Commands 15 internal enum Commands
16 { 16 {
@@ -22,12 +22,14 @@ namespace WixToolset.Core
22 Bind, 22 Bind,
23 } 23 }
24 24
25 public class CommandLine 25 internal class CommandLine : ICommandLine
26 { 26 {
27 private CommandLine() 27 public CommandLine()
28 { 28 {
29 } 29 }
30 30
31 private IServiceProvider ServiceProvider { get; set; }
32
31 public static string ExpectedArgument { get; } = "expected argument"; 33 public static string ExpectedArgument { get; } = "expected argument";
32 34
33 public string ActiveCommand { get; private set; } 35 public string ActiveCommand { get; private set; }
@@ -36,20 +38,29 @@ namespace WixToolset.Core
36 38
37 public Queue<string> RemainingArguments { get; } = new Queue<string>(); 39 public Queue<string> RemainingArguments { get; } = new Queue<string>();
38 40
39 public ExtensionManager ExtensionManager { get; } = new ExtensionManager(); 41 public IExtensionManager ExtensionManager { get; private set; }
40 42
41 public string ErrorArgument { get; set; } 43 public string ErrorArgument { get; set; }
42 44
43 public bool ShowHelp { get; set; } 45 public bool ShowHelp { get; set; }
44 46
45 public static ICommandLineCommand ParseStandardCommandLine(string commandLineString) 47 public ICommandLineCommand ParseStandardCommandLine(ICommandLineContext context)
46 { 48 {
47 var args = CommandLine.ParseArgumentsToArray(commandLineString).ToArray(); 49 this.ServiceProvider = context.ServiceProvider;
50
51 this.ExtensionManager = context.ExtensionManager ?? this.ServiceProvider.GetService<IExtensionManager>();
52
53 var args = context.ParsedArguments ?? Array.Empty<string>();
54
55 if (!String.IsNullOrEmpty(context.Arguments))
56 {
57 args = CommandLine.ParseArgumentsToArray(context.Arguments).Union(args).ToArray();
58 }
48 59
49 return ParseStandardCommandLine(args); 60 return this.ParseStandardCommandLine(args);
50 } 61 }
51 62
52 public static ICommandLineCommand ParseStandardCommandLine(string[] args) 63 private ICommandLineCommand ParseStandardCommandLine(string[] args)
53 { 64 {
54 var next = String.Empty; 65 var next = String.Empty;
55 66
@@ -79,7 +90,7 @@ namespace WixToolset.Core
79 var builtOutputsFile = String.Empty; 90 var builtOutputsFile = String.Empty;
80 var wixProjectFile = String.Empty; 91 var wixProjectFile = String.Empty;
81 92
82 var cli = CommandLine.Parse(args, (cmdline, arg) => Enum.TryParse(arg, true, out command), (cmdline, arg) => 93 this.Parse(args, (cmdline, arg) => Enum.TryParse(arg, true, out command), (cmdline, arg) =>
83 { 94 {
84 if (cmdline.IsSwitch(arg)) 95 if (cmdline.IsSwitch(arg))
85 { 96 {
@@ -103,7 +114,7 @@ namespace WixToolset.Core
103 case "cc": 114 case "cc":
104 cmdline.GetNextArgumentOrError(ref cabCachePath); 115 cmdline.GetNextArgumentOrError(ref cabCachePath);
105 return true; 116 return true;
106 117
107 case "cultures": 118 case "cultures":
108 cmdline.GetNextArgumentOrError(cultures); 119 cmdline.GetNextArgumentOrError(cultures);
109 return true; 120 return true;
@@ -187,7 +198,7 @@ namespace WixToolset.Core
187 AppCommon.DisplayToolHeader(); 198 AppCommon.DisplayToolHeader();
188 } 199 }
189 200
190 if (cli.ShowHelp) 201 if (this.ShowHelp)
191 { 202 {
192 return new HelpCommand(command); 203 return new HelpCommand(command);
193 } 204 }
@@ -196,14 +207,11 @@ namespace WixToolset.Core
196 { 207 {
197 case Commands.Build: 208 case Commands.Build:
198 { 209 {
199 LoadStandardBackends(cli.ExtensionManager);
200
201 var sourceFiles = GatherSourceFiles(files, outputFolder); 210 var sourceFiles = GatherSourceFiles(files, outputFolder);
202 var variables = GatherPreprocessorVariables(defines); 211 var variables = GatherPreprocessorVariables(defines);
203 var bindPathList = GatherBindPaths(bindPaths); 212 var bindPathList = GatherBindPaths(bindPaths);
204 var extensions = cli.ExtensionManager;
205 var type = CalculateOutputType(outputType, outputFile); 213 var type = CalculateOutputType(outputType, outputFile);
206 return new BuildCommand(extensions, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cabCachePath, cultures, bindFiles, bindPathList, intermediateFolder, contentsFile, outputsFile, builtOutputsFile, wixProjectFile); 214 return new BuildCommand(this.ServiceProvider, this.ExtensionManager, sourceFiles, variables, locFiles, libraryFiles, outputFile, type, cabCachePath, cultures, bindFiles, bindPathList, intermediateFolder, contentsFile, outputsFile, builtOutputsFile, wixProjectFile);
207 } 215 }
208 216
209 case Commands.Compile: 217 case Commands.Compile:
@@ -217,18 +225,6 @@ namespace WixToolset.Core
217 return null; 225 return null;
218 } 226 }
219 227
220 private static void LoadStandardBackends(ExtensionManager extensionManager)
221 {
222 var folder = Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath);
223
224 foreach (var backendAssemblyName in new[] { "WixToolset.Core.Burn.dll", "WixToolset.Core.WindowsInstaller.dll" })
225 {
226 var path = Path.Combine(folder, backendAssemblyName);
227
228 extensionManager.Load(path);
229 }
230 }
231
232 private static OutputType CalculateOutputType(string outputType, string outputFile) 228 private static OutputType CalculateOutputType(string outputType, string outputFile)
233 { 229 {
234 if (String.IsNullOrEmpty(outputType)) 230 if (String.IsNullOrEmpty(outputType))
@@ -269,6 +265,7 @@ namespace WixToolset.Core
269 return OutputType.Unknown; 265 return OutputType.Unknown;
270 } 266 }
271 267
268#if UNUSED
272 private static CommandLine Parse(string commandLineString, Func<CommandLine, string, bool> parseArgument) 269 private static CommandLine Parse(string commandLineString, Func<CommandLine, string, bool> parseArgument)
273 { 270 {
274 var arguments = CommandLine.ParseArgumentsToArray(commandLineString).ToArray(); 271 var arguments = CommandLine.ParseArgumentsToArray(commandLineString).ToArray();
@@ -280,18 +277,17 @@ namespace WixToolset.Core
280 { 277 {
281 return CommandLine.Parse(commandLineArguments, null, parseArgument); 278 return CommandLine.Parse(commandLineArguments, null, parseArgument);
282 } 279 }
280#endif
283 281
284 private static CommandLine Parse(string[] commandLineArguments, Func<CommandLine, string, bool> parseCommand, Func<CommandLine, string, bool> parseArgument) 282 private ICommandLine Parse(string[] commandLineArguments, Func<CommandLine, string, bool> parseCommand, Func<CommandLine, string, bool> parseArgument)
285 { 283 {
286 var cmdline = new CommandLine(); 284 this.FlattenArgumentsWithResponseFilesIntoOriginalArguments(commandLineArguments);
287
288 cmdline.FlattenArgumentsWithResponseFilesIntoOriginalArguments(commandLineArguments);
289 285
290 cmdline.QueueArgumentsAndLoadExtensions(cmdline.OriginalArguments); 286 this.QueueArgumentsAndLoadExtensions(this.OriginalArguments);
291 287
292 cmdline.ProcessRemainingArguments(parseArgument, parseCommand); 288 this.ProcessRemainingArguments(parseArgument, parseCommand);
293 289
294 return cmdline; 290 return this;
295 } 291 }
296 292
297 private static IEnumerable<SourceFile> GatherSourceFiles(IEnumerable<string> sourceFiles, string intermediateDirectory) 293 private static IEnumerable<SourceFile> GatherSourceFiles(IEnumerable<string> sourceFiles, string intermediateDirectory)
diff --git a/src/WixToolset.Core/CommandLine/CommandLineContext.cs b/src/WixToolset.Core/CommandLine/CommandLineContext.cs
new file mode 100644
index 00000000..96c149be
--- /dev/null
+++ b/src/WixToolset.Core/CommandLine/CommandLineContext.cs
@@ -0,0 +1,26 @@
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
3namespace WixToolset.Core
4{
5 using System;
6 using WixToolset.Data;
7 using WixToolset.Extensibility.Services;
8
9 internal class CommandLineContext : ICommandLineContext
10 {
11 public CommandLineContext(IServiceProvider serviceProvider)
12 {
13 this.ServiceProvider = serviceProvider;
14 }
15
16 public IServiceProvider ServiceProvider { get; }
17
18 public Messaging Messaging { get; set; }
19
20 public IExtensionManager ExtensionManager { get; set; }
21
22 public string Arguments { get; set; }
23
24 public string[] ParsedArguments { get; set; }
25 }
26}
diff --git a/src/WixToolset.Core/CommandLine/CompileCommand.cs b/src/WixToolset.Core/CommandLine/CompileCommand.cs
index bbcc8270..855e7c6a 100644
--- a/src/WixToolset.Core/CommandLine/CompileCommand.cs
+++ b/src/WixToolset.Core/CommandLine/CompileCommand.cs
@@ -2,9 +2,8 @@
2 2
3namespace WixToolset.Core 3namespace WixToolset.Core
4{ 4{
5 using System;
6 using System.Collections.Generic; 5 using System.Collections.Generic;
7 using WixToolset.Data; 6 using WixToolset.Extensibility.Services;
8 7
9 internal class CompileCommand : ICommandLineCommand 8 internal class CompileCommand : ICommandLineCommand
10 { 9 {
diff --git a/src/WixToolset.Core/CommandLine/HelpCommand.cs b/src/WixToolset.Core/CommandLine/HelpCommand.cs
index e57ad132..2a2eab24 100644
--- a/src/WixToolset.Core/CommandLine/HelpCommand.cs
+++ b/src/WixToolset.Core/CommandLine/HelpCommand.cs
@@ -3,6 +3,7 @@
3namespace WixToolset.Core 3namespace WixToolset.Core
4{ 4{
5 using System; 5 using System;
6 using WixToolset.Extensibility.Services;
6 7
7 internal class HelpCommand : ICommandLineCommand 8 internal class HelpCommand : ICommandLineCommand
8 { 9 {
diff --git a/src/WixToolset.Core/CommandLine/ICommandLineCommand.cs b/src/WixToolset.Core/CommandLine/ICommandLineCommand.cs
deleted file mode 100644
index f1471355..00000000
--- a/src/WixToolset.Core/CommandLine/ICommandLineCommand.cs
+++ /dev/null
@@ -1,9 +0,0 @@
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
3namespace WixToolset.Core
4{
5 public interface ICommandLineCommand
6 {
7 int Execute();
8 }
9}
diff --git a/src/WixToolset.Core/CommandLine/VersionCommand.cs b/src/WixToolset.Core/CommandLine/VersionCommand.cs
index d13e07a3..12941bdc 100644
--- a/src/WixToolset.Core/CommandLine/VersionCommand.cs
+++ b/src/WixToolset.Core/CommandLine/VersionCommand.cs
@@ -1,9 +1,10 @@
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. 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 2
3using System;
4
5namespace WixToolset.Core 3namespace WixToolset.Core
6{ 4{
5 using System;
6 using WixToolset.Extensibility.Services;
7
7 internal class VersionCommand : ICommandLineCommand 8 internal class VersionCommand : ICommandLineCommand
8 { 9 {
9 public int Execute() 10 public int Execute()
diff --git a/src/WixToolset.Core/ExtensionManager.cs b/src/WixToolset.Core/ExtensionManager.cs
index 7e40571b..b9038c6a 100644
--- a/src/WixToolset.Core/ExtensionManager.cs
+++ b/src/WixToolset.Core/ExtensionManager.cs
@@ -1,6 +1,6 @@
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. 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 2
3namespace WixToolset 3namespace WixToolset.Core
4{ 4{
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
@@ -8,13 +8,24 @@ namespace WixToolset
8 using System.Linq; 8 using System.Linq;
9 using System.Reflection; 9 using System.Reflection;
10 using WixToolset.Data; 10 using WixToolset.Data;
11 using WixToolset.Extensibility; 11 using WixToolset.Extensibility.Services;
12 12
13 public class ExtensionManager : IExtensionManager 13 public class ExtensionManager : IExtensionManager
14 { 14 {
15 private List<Assembly> extensionAssemblies = new List<Assembly>(); 15 private List<Assembly> extensionAssemblies = new List<Assembly>();
16 16
17 /// <summary> 17 /// <summary>
18 /// Adds an assembly.
19 /// </summary>
20 /// <param name="assembly">Assembly to add to the extension manager.</param>
21 /// <returns>The assembly added.</returns>
22 public Assembly Add(Assembly assembly)
23 {
24 this.extensionAssemblies.Add(assembly);
25 return assembly;
26 }
27
28 /// <summary>
18 /// Loads an assembly from a type description string. 29 /// Loads an assembly from a type description string.
19 /// </summary> 30 /// </summary>
20 /// <param name="extension">The assembly type description string.</param> 31 /// <param name="extension">The assembly type description string.</param>
@@ -57,8 +68,7 @@ namespace WixToolset
57 assembly = ExtensionManager.ExtensionLoadFrom(assemblyName); 68 assembly = ExtensionManager.ExtensionLoadFrom(assemblyName);
58 } 69 }
59 70
60 this.extensionAssemblies.Add(assembly); 71 return this.Add(assembly);
61 return assembly;
62 } 72 }
63 73
64 /// <summary> 74 /// <summary>
diff --git a/src/WixToolset.Core/IncribeContext.cs b/src/WixToolset.Core/IncribeContext.cs
index 604ba5d1..15dd3664 100644
--- a/src/WixToolset.Core/IncribeContext.cs
+++ b/src/WixToolset.Core/IncribeContext.cs
@@ -2,11 +2,19 @@
2 2
3namespace WixToolset.Core 3namespace WixToolset.Core
4{ 4{
5 using System;
5 using WixToolset.Data; 6 using WixToolset.Data;
6 using WixToolset.Extensibility; 7 using WixToolset.Extensibility;
7 8
8 internal class InscribeContext : IInscribeContext 9 internal class InscribeContext : IInscribeContext
9 { 10 {
11 public InscribeContext(IServiceProvider serviceProvider)
12 {
13 this.ServiceProvider = serviceProvider;
14 }
15
16 public IServiceProvider ServiceProvider { get; }
17
10 public Messaging Messaging { get; } = Messaging.Instance; 18 public Messaging Messaging { get; } = Messaging.Instance;
11 19
12 public string IntermediateFolder { get; set; } 20 public string IntermediateFolder { get; set; }
diff --git a/src/WixToolset.Core/WixToolsetServiceProvider.cs b/src/WixToolset.Core/WixToolsetServiceProvider.cs
new file mode 100644
index 00000000..c073c32b
--- /dev/null
+++ b/src/WixToolset.Core/WixToolsetServiceProvider.cs
@@ -0,0 +1,47 @@
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
3namespace WixToolset.Core
4{
5 using System;
6 using WixToolset.Extensibility;
7 using WixToolset.Extensibility.Services;
8
9 public class WixToolsetServiceProvider : IServiceProvider
10 {
11 private ExtensionManager extensionManager;
12
13 public object GetService(Type serviceType)
14 {
15 if (serviceType == null) throw new ArgumentNullException(nameof(serviceType));
16
17 // Transients.
18 if (serviceType == typeof(IBindContext))
19 {
20 return new BindContext(this);
21 }
22
23 if (serviceType == typeof(IInscribeContext))
24 {
25 return new InscribeContext(this);
26 }
27
28 if (serviceType == typeof(ICommandLineContext))
29 {
30 return new CommandLineContext(this);
31 }
32
33 if (serviceType == typeof(ICommandLine))
34 {
35 return new CommandLine();
36 }
37
38 // Singletons.
39 if (serviceType == typeof(IExtensionManager))
40 {
41 return extensionManager = extensionManager ?? new ExtensionManager();
42 }
43
44 throw new ArgumentException($"Unknown service type: {serviceType.Name}", nameof(serviceType));
45 }
46 }
47}