From c66c3694ba182fbc0b86b0745563f9ee790d907f Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Thu, 2 Apr 2020 20:09:20 +1000 Subject: Add IWixToolsetServiceProvider and IWixToolsetCoreServiceProvider to expose the more convenient methods from WixToolsetServiceProvider without requiring casting or extension methods. --- src/WixToolset.Extensibility/BaseExtensionFactory.cs | 2 ++ src/WixToolset.Extensibility/Data/IBindContext.cs | 3 ++- src/WixToolset.Extensibility/Data/ICommandLineContext.cs | 4 ++-- src/WixToolset.Extensibility/Data/ICompileContext.cs | 5 +++-- src/WixToolset.Extensibility/Data/IDecompileContext.cs | 3 ++- src/WixToolset.Extensibility/Data/IFileSystemContext.cs | 5 +++-- src/WixToolset.Extensibility/Data/IInscribeContext.cs | 5 +++-- src/WixToolset.Extensibility/Data/ILayoutContext.cs | 5 +++-- src/WixToolset.Extensibility/Data/ILibraryContext.cs | 3 ++- src/WixToolset.Extensibility/Data/ILinkContext.cs | 5 +++-- src/WixToolset.Extensibility/Data/IPreprocessContext.cs | 3 ++- src/WixToolset.Extensibility/Data/IResolveContext.cs | 3 ++- src/WixToolset.Extensibility/Data/IUnbindContext.cs | 5 +++-- src/WixToolset.Extensibility/IExtensionFactory.cs | 5 ++++- .../Services/IWixToolsetServiceProvider.cs | 13 +++++++++++++ .../Services/IWixtoolsetCoreServiceProvider.cs | 13 +++++++++++++ .../Services/ServiceProviderExtensions.cs | 14 -------------- 17 files changed, 62 insertions(+), 34 deletions(-) create mode 100644 src/WixToolset.Extensibility/Services/IWixToolsetServiceProvider.cs create mode 100644 src/WixToolset.Extensibility/Services/IWixtoolsetCoreServiceProvider.cs delete mode 100644 src/WixToolset.Extensibility/Services/ServiceProviderExtensions.cs (limited to 'src') diff --git a/src/WixToolset.Extensibility/BaseExtensionFactory.cs b/src/WixToolset.Extensibility/BaseExtensionFactory.cs index 2e7fdbb8..d0686b46 100644 --- a/src/WixToolset.Extensibility/BaseExtensionFactory.cs +++ b/src/WixToolset.Extensibility/BaseExtensionFactory.cs @@ -7,6 +7,8 @@ namespace WixToolset.Extensibility /// /// Base class for extension factories. + /// + /// Implementations may request an IWixToolsetCoreServiceProvider at instantiation by having a single parameter constructor for it. /// public abstract class BaseExtensionFactory : IExtensionFactory { diff --git a/src/WixToolset.Extensibility/Data/IBindContext.cs b/src/WixToolset.Extensibility/Data/IBindContext.cs index b6e51d6d..87e61d53 100644 --- a/src/WixToolset.Extensibility/Data/IBindContext.cs +++ b/src/WixToolset.Extensibility/Data/IBindContext.cs @@ -5,10 +5,11 @@ namespace WixToolset.Extensibility.Data using System; using System.Collections.Generic; using WixToolset.Data; + using WixToolset.Extensibility.Services; public interface IBindContext { - IServiceProvider ServiceProvider { get; } + IWixToolsetServiceProvider ServiceProvider { get; } string BurnStubPath { get; set; } diff --git a/src/WixToolset.Extensibility/Data/ICommandLineContext.cs b/src/WixToolset.Extensibility/Data/ICommandLineContext.cs index 1b2db4a4..41c913fe 100644 --- a/src/WixToolset.Extensibility/Data/ICommandLineContext.cs +++ b/src/WixToolset.Extensibility/Data/ICommandLineContext.cs @@ -1,4 +1,4 @@ -// 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. +// 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. namespace WixToolset.Extensibility.Data { @@ -7,7 +7,7 @@ namespace WixToolset.Extensibility.Data public interface ICommandLineContext { - IServiceProvider ServiceProvider { get; } + IWixToolsetServiceProvider ServiceProvider { get; } IExtensionManager ExtensionManager { get; set; } diff --git a/src/WixToolset.Extensibility/Data/ICompileContext.cs b/src/WixToolset.Extensibility/Data/ICompileContext.cs index 50ad10b9..ef57f6d0 100644 --- a/src/WixToolset.Extensibility/Data/ICompileContext.cs +++ b/src/WixToolset.Extensibility/Data/ICompileContext.cs @@ -1,4 +1,4 @@ -// 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. +// 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. namespace WixToolset.Extensibility.Data { @@ -6,10 +6,11 @@ namespace WixToolset.Extensibility.Data using System.Collections.Generic; using System.Xml.Linq; using WixToolset.Data; + using WixToolset.Extensibility.Services; public interface ICompileContext { - IServiceProvider ServiceProvider { get; } + IWixToolsetServiceProvider ServiceProvider { get; } string CompilationId { get; set; } diff --git a/src/WixToolset.Extensibility/Data/IDecompileContext.cs b/src/WixToolset.Extensibility/Data/IDecompileContext.cs index f61fd84a..29d6fb3b 100644 --- a/src/WixToolset.Extensibility/Data/IDecompileContext.cs +++ b/src/WixToolset.Extensibility/Data/IDecompileContext.cs @@ -5,10 +5,11 @@ namespace WixToolset.Extensibility.Data using System; using System.Collections.Generic; using WixToolset.Data; + using WixToolset.Extensibility.Services; public interface IDecompileContext { - IServiceProvider ServiceProvider { get; } + IWixToolsetServiceProvider ServiceProvider { get; } string DecompilePath { get; set; } diff --git a/src/WixToolset.Extensibility/Data/IFileSystemContext.cs b/src/WixToolset.Extensibility/Data/IFileSystemContext.cs index 86fc106c..f27e16d5 100644 --- a/src/WixToolset.Extensibility/Data/IFileSystemContext.cs +++ b/src/WixToolset.Extensibility/Data/IFileSystemContext.cs @@ -1,13 +1,14 @@ -// 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. +// 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. namespace WixToolset.Extensibility.Data { using System; using WixToolset.Data; + using WixToolset.Extensibility.Services; public interface IFileSystemContext { - IServiceProvider ServiceProvider { get; } + IWixToolsetServiceProvider ServiceProvider { get; } string CabCachePath { get; set; } diff --git a/src/WixToolset.Extensibility/Data/IInscribeContext.cs b/src/WixToolset.Extensibility/Data/IInscribeContext.cs index 4f13ba10..816a0c80 100644 --- a/src/WixToolset.Extensibility/Data/IInscribeContext.cs +++ b/src/WixToolset.Extensibility/Data/IInscribeContext.cs @@ -1,12 +1,13 @@ -// 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. +// 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. namespace WixToolset.Extensibility.Data { using System; + using WixToolset.Extensibility.Services; public interface IInscribeContext { - IServiceProvider ServiceProvider { get; } + IWixToolsetServiceProvider ServiceProvider { get; } string InputFilePath { get; set; } diff --git a/src/WixToolset.Extensibility/Data/ILayoutContext.cs b/src/WixToolset.Extensibility/Data/ILayoutContext.cs index 5c0a46c7..721c5094 100644 --- a/src/WixToolset.Extensibility/Data/ILayoutContext.cs +++ b/src/WixToolset.Extensibility/Data/ILayoutContext.cs @@ -1,13 +1,14 @@ -// 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. +// 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. namespace WixToolset.Extensibility.Data { using System; using System.Collections.Generic; + using WixToolset.Extensibility.Services; public interface ILayoutContext { - IServiceProvider ServiceProvider { get; } + IWixToolsetServiceProvider ServiceProvider { get; } IEnumerable Extensions { get; set; } diff --git a/src/WixToolset.Extensibility/Data/ILibraryContext.cs b/src/WixToolset.Extensibility/Data/ILibraryContext.cs index 9b65ebfd..0371137b 100644 --- a/src/WixToolset.Extensibility/Data/ILibraryContext.cs +++ b/src/WixToolset.Extensibility/Data/ILibraryContext.cs @@ -5,10 +5,11 @@ namespace WixToolset.Extensibility.Data using System; using System.Collections.Generic; using WixToolset.Data; + using WixToolset.Extensibility.Services; public interface ILibraryContext { - IServiceProvider ServiceProvider { get; } + IWixToolsetServiceProvider ServiceProvider { get; } bool BindFiles { get; set; } diff --git a/src/WixToolset.Extensibility/Data/ILinkContext.cs b/src/WixToolset.Extensibility/Data/ILinkContext.cs index 8c1d6f22..4212339e 100644 --- a/src/WixToolset.Extensibility/Data/ILinkContext.cs +++ b/src/WixToolset.Extensibility/Data/ILinkContext.cs @@ -1,14 +1,15 @@ -// 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. +// 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. namespace WixToolset.Extensibility.Data { using System; using System.Collections.Generic; using WixToolset.Data; + using WixToolset.Extensibility.Services; public interface ILinkContext { - IServiceProvider ServiceProvider { get; } + IWixToolsetServiceProvider ServiceProvider { get; } IEnumerable Extensions { get; set; } diff --git a/src/WixToolset.Extensibility/Data/IPreprocessContext.cs b/src/WixToolset.Extensibility/Data/IPreprocessContext.cs index 42dfbb75..89cbdd5d 100644 --- a/src/WixToolset.Extensibility/Data/IPreprocessContext.cs +++ b/src/WixToolset.Extensibility/Data/IPreprocessContext.cs @@ -5,10 +5,11 @@ namespace WixToolset.Extensibility.Data using System; using System.Collections.Generic; using WixToolset.Data; + using WixToolset.Extensibility.Services; public interface IPreprocessContext { - IServiceProvider ServiceProvider { get; } + IWixToolsetServiceProvider ServiceProvider { get; } IEnumerable Extensions { get; set; } diff --git a/src/WixToolset.Extensibility/Data/IResolveContext.cs b/src/WixToolset.Extensibility/Data/IResolveContext.cs index 608ce5d5..95845317 100644 --- a/src/WixToolset.Extensibility/Data/IResolveContext.cs +++ b/src/WixToolset.Extensibility/Data/IResolveContext.cs @@ -5,10 +5,11 @@ namespace WixToolset.Extensibility.Data using System; using System.Collections.Generic; using WixToolset.Data; + using WixToolset.Extensibility.Services; public interface IResolveContext { - IServiceProvider ServiceProvider { get; } + IWixToolsetServiceProvider ServiceProvider { get; } IEnumerable BindPaths { get; set; } diff --git a/src/WixToolset.Extensibility/Data/IUnbindContext.cs b/src/WixToolset.Extensibility/Data/IUnbindContext.cs index 84dc5167..bdc31240 100644 --- a/src/WixToolset.Extensibility/Data/IUnbindContext.cs +++ b/src/WixToolset.Extensibility/Data/IUnbindContext.cs @@ -1,12 +1,13 @@ -// 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. +// 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. namespace WixToolset.Extensibility.Data { using System; + using WixToolset.Extensibility.Services; public interface IUnbindContext { - IServiceProvider ServiceProvider { get; } + IWixToolsetServiceProvider ServiceProvider { get; } string ExportBasePath { get; set; } diff --git a/src/WixToolset.Extensibility/IExtensionFactory.cs b/src/WixToolset.Extensibility/IExtensionFactory.cs index 234f64fa..f86fdde0 100644 --- a/src/WixToolset.Extensibility/IExtensionFactory.cs +++ b/src/WixToolset.Extensibility/IExtensionFactory.cs @@ -1,9 +1,12 @@ -// 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. +// 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. namespace WixToolset.Extensibility { using System; + /// + /// Implementations may request an IWixToolsetCoreServiceProvider at instantiation by having a single parameter constructor for it. + /// public interface IExtensionFactory { /// diff --git a/src/WixToolset.Extensibility/Services/IWixToolsetServiceProvider.cs b/src/WixToolset.Extensibility/Services/IWixToolsetServiceProvider.cs new file mode 100644 index 00000000..c9ef36e1 --- /dev/null +++ b/src/WixToolset.Extensibility/Services/IWixToolsetServiceProvider.cs @@ -0,0 +1,13 @@ +// 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. + +namespace WixToolset.Extensibility.Services +{ + using System; + + public interface IWixToolsetServiceProvider : IServiceProvider + { + bool TryGetService(Type serviceType, out object service); + bool TryGetService(out T service) where T : class; + T GetService() where T : class; + } +} diff --git a/src/WixToolset.Extensibility/Services/IWixtoolsetCoreServiceProvider.cs b/src/WixToolset.Extensibility/Services/IWixtoolsetCoreServiceProvider.cs new file mode 100644 index 00000000..cda725f7 --- /dev/null +++ b/src/WixToolset.Extensibility/Services/IWixtoolsetCoreServiceProvider.cs @@ -0,0 +1,13 @@ +// 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. + +namespace WixToolset.Extensibility.Services +{ + using System; + using System.Collections.Generic; + + public interface IWixToolsetCoreServiceProvider : IWixToolsetServiceProvider + { + void AddService(Type serviceType, Func, object> creationFunction); + void AddService(Func, T> creationFunction) where T : class; + } +} diff --git a/src/WixToolset.Extensibility/Services/ServiceProviderExtensions.cs b/src/WixToolset.Extensibility/Services/ServiceProviderExtensions.cs deleted file mode 100644 index f4a5e8c3..00000000 --- a/src/WixToolset.Extensibility/Services/ServiceProviderExtensions.cs +++ /dev/null @@ -1,14 +0,0 @@ -// 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. - -namespace WixToolset.Extensibility.Services -{ - using System; - - public static class ServiceProviderExtensions - { - public static T GetService(this IServiceProvider serviceProvider) where T : class - { - return (T)serviceProvider.GetService(typeof(T)); - } - } -} -- cgit v1.2.3-55-g6feb