diff options
Diffstat (limited to 'src/WixToolset.Core/WixToolsetServiceProvider.cs')
-rw-r--r-- | src/WixToolset.Core/WixToolsetServiceProvider.cs | 47 |
1 files changed, 47 insertions, 0 deletions
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 | |||
3 | namespace 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 | } | ||