Add IWixToolsetServiceProvider and IWixToolsetCoreServiceProvider to expose the more convenient methods from WixToolsetServiceProvider without requiring casting or extension methods.
Sean Hall committed
Apr 2, 2020 at 20:09 UTC
c66c3694ba182fbc0b86b0745563f9ee790d907f
17 files changed
+62
-34
src/WixToolset.Extensibility/BaseExtensionFactory.cs
+2
@@ -7,6 +7,8 @@ namespace WixToolset.Extensibility
7
8
/// <summary>
9
/// Base class for extension factories.
10
+ ///
11
+ /// Implementations may request an IWixToolsetCoreServiceProvider at instantiation by having a single parameter constructor for it.
12
/// </summary>
13
public abstract class BaseExtensionFactory : IExtensionFactory
14
{
src/WixToolset.Extensibility/Data/IBindContext.cs
+2
-1
@@ -5,10 +5,11 @@ namespace WixToolset.Extensibility.Data
5
using System;
6
using System.Collections.Generic;
7
using WixToolset.Data;
8
+ using WixToolset.Extensibility.Services;
9
10
public interface IBindContext
11
{
11
- IServiceProvider ServiceProvider { get; }
12
+ IWixToolsetServiceProvider ServiceProvider { get; }
13
14
string BurnStubPath { get; set; }
15
src/WixToolset.Extensibility/Data/ICommandLineContext.cs
+2
-2
@@ -1,4 +1,4 @@
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
3
namespace WixToolset.Extensibility.Data
4
{
@@ -7,7 +7,7 @@ namespace WixToolset.Extensibility.Data
7
8
public interface ICommandLineContext
9
{
10
- IServiceProvider ServiceProvider { get; }
10
+ IWixToolsetServiceProvider ServiceProvider { get; }
11
12
IExtensionManager ExtensionManager { get; set; }
13
src/WixToolset.Extensibility/Data/ICompileContext.cs
+3
-2
@@ -1,4 +1,4 @@
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
3
namespace WixToolset.Extensibility.Data
4
{
@@ -6,10 +6,11 @@ namespace WixToolset.Extensibility.Data
6
using System.Collections.Generic;
7
using System.Xml.Linq;
8
using WixToolset.Data;
9
+ using WixToolset.Extensibility.Services;
10
11
public interface ICompileContext
12
{
12
- IServiceProvider ServiceProvider { get; }
13
+ IWixToolsetServiceProvider ServiceProvider { get; }
14
15
string CompilationId { get; set; }
16
src/WixToolset.Extensibility/Data/IDecompileContext.cs
+2
-1
@@ -5,10 +5,11 @@ namespace WixToolset.Extensibility.Data
5
using System;
6
using System.Collections.Generic;
7
using WixToolset.Data;
8
+ using WixToolset.Extensibility.Services;
9
10
public interface IDecompileContext
11
{
11
- IServiceProvider ServiceProvider { get; }
12
+ IWixToolsetServiceProvider ServiceProvider { get; }
13
14
string DecompilePath { get; set; }
15
src/WixToolset.Extensibility/Data/IFileSystemContext.cs
+3
-2
@@ -1,13 +1,14 @@
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
3
namespace WixToolset.Extensibility.Data
4
{
5
using System;
6
using WixToolset.Data;
7
+ using WixToolset.Extensibility.Services;
8
9
public interface IFileSystemContext
10
{
10
- IServiceProvider ServiceProvider { get; }
11
+ IWixToolsetServiceProvider ServiceProvider { get; }
12
13
string CabCachePath { get; set; }
14
src/WixToolset.Extensibility/Data/IInscribeContext.cs
+3
-2
@@ -1,12 +1,13 @@
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
3
namespace WixToolset.Extensibility.Data
4
{
5
using System;
6
+ using WixToolset.Extensibility.Services;
7
8
public interface IInscribeContext
9
{
9
- IServiceProvider ServiceProvider { get; }
10
+ IWixToolsetServiceProvider ServiceProvider { get; }
11
12
string InputFilePath { get; set; }
13
src/WixToolset.Extensibility/Data/ILayoutContext.cs
+3
-2
@@ -1,13 +1,14 @@
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
3
namespace WixToolset.Extensibility.Data
4
{
5
using System;
6
using System.Collections.Generic;
7
+ using WixToolset.Extensibility.Services;
8
9
public interface ILayoutContext
10
{
10
- IServiceProvider ServiceProvider { get; }
11
+ IWixToolsetServiceProvider ServiceProvider { get; }
12
13
IEnumerable<ILayoutExtension> Extensions { get; set; }
14
src/WixToolset.Extensibility/Data/ILibraryContext.cs
+2
-1
@@ -5,10 +5,11 @@ namespace WixToolset.Extensibility.Data
5
using System;
6
using System.Collections.Generic;
7
using WixToolset.Data;
8
+ using WixToolset.Extensibility.Services;
9
10
public interface ILibraryContext
11
{
11
- IServiceProvider ServiceProvider { get; }
12
+ IWixToolsetServiceProvider ServiceProvider { get; }
13
14
bool BindFiles { get; set; }
15
src/WixToolset.Extensibility/Data/ILinkContext.cs
+3
-2
@@ -1,14 +1,15 @@
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
3
namespace WixToolset.Extensibility.Data
4
{
5
using System;
6
using System.Collections.Generic;
7
using WixToolset.Data;
8
+ using WixToolset.Extensibility.Services;
9
10
public interface ILinkContext
11
{
11
- IServiceProvider ServiceProvider { get; }
12
+ IWixToolsetServiceProvider ServiceProvider { get; }
13
14
IEnumerable<ILinkerExtension> Extensions { get; set; }
15
src/WixToolset.Extensibility/Data/IPreprocessContext.cs
+2
-1
@@ -5,10 +5,11 @@ namespace WixToolset.Extensibility.Data
5
using System;
6
using System.Collections.Generic;
7
using WixToolset.Data;
8
+ using WixToolset.Extensibility.Services;
9
10
public interface IPreprocessContext
11
{
11
- IServiceProvider ServiceProvider { get; }
12
+ IWixToolsetServiceProvider ServiceProvider { get; }
13
14
IEnumerable<IPreprocessorExtension> Extensions { get; set; }
15
src/WixToolset.Extensibility/Data/IResolveContext.cs
+2
-1
@@ -5,10 +5,11 @@ namespace WixToolset.Extensibility.Data
5
using System;
6
using System.Collections.Generic;
7
using WixToolset.Data;
8
+ using WixToolset.Extensibility.Services;
9
10
public interface IResolveContext
11
{
11
- IServiceProvider ServiceProvider { get; }
12
+ IWixToolsetServiceProvider ServiceProvider { get; }
13
14
IEnumerable<IBindPath> BindPaths { get; set; }
15
src/WixToolset.Extensibility/Data/IUnbindContext.cs
+3
-2
@@ -1,12 +1,13 @@
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
3
namespace WixToolset.Extensibility.Data
4
{
5
using System;
6
+ using WixToolset.Extensibility.Services;
7
8
public interface IUnbindContext
9
{
9
- IServiceProvider ServiceProvider { get; }
10
+ IWixToolsetServiceProvider ServiceProvider { get; }
11
12
string ExportBasePath { get; set; }
13
src/WixToolset.Extensibility/IExtensionFactory.cs
+4
-1
@@ -1,9 +1,12 @@
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
3
namespace WixToolset.Extensibility
4
{
5
using System;
6
7
+ /// <summary>
8
+ /// Implementations may request an IWixToolsetCoreServiceProvider at instantiation by having a single parameter constructor for it.
9
+ /// </summary>
10
public interface IExtensionFactory
11
{
12
/// <summary>
src/WixToolset.Extensibility/Services/IWixToolsetServiceProvider.cs
new
+13
@@ -0,0 +1,13 @@
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.Services
4
+{
5
+ using System;
6
+
7
+ public interface IWixToolsetServiceProvider : IServiceProvider
8
+ {
9
+ bool TryGetService(Type serviceType, out object service);
10
+ bool TryGetService<T>(out T service) where T : class;
11
+ T GetService<T>() where T : class;
12
+ }
13
+}
src/WixToolset.Extensibility/Services/IWixtoolsetCoreServiceProvider.cs
new
+13
@@ -0,0 +1,13 @@
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.Services
4
+{
5
+ using System;
6
+ using System.Collections.Generic;
7
+
8
+ public interface IWixToolsetCoreServiceProvider : IWixToolsetServiceProvider
9
+ {
10
+ void AddService(Type serviceType, Func<IWixToolsetCoreServiceProvider, Dictionary<Type, object>, object> creationFunction);
11
+ void AddService<T>(Func<IWixToolsetCoreServiceProvider, Dictionary<Type, object>, T> creationFunction) where T : class;
12
+ }
13
+}
src/WixToolset.Extensibility/Services/ServiceProviderExtensions.cs
deleted
-14
@@ -1,14 +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
-
3
-namespace WixToolset.Extensibility.Services
4
-{
5
- using System;
6
-
7
- public static class ServiceProviderExtensions
8
- {
9
- public static T GetService<T>(this IServiceProvider serviceProvider) where T : class
10
- {
11
- return (T)serviceProvider.GetService(typeof(T));
12
- }
13
- }
14
-}