| 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.Burn |
| 4 | { |
| 5 | using System; |
| 6 | using System.Collections.Generic; |
| 7 | using WixToolset.Core.Burn.ExtensibilityServices; |
| 8 | using WixToolset.Core.Burn.Interfaces; |
| 9 | using WixToolset.Extensibility.Services; |
| 10 | |
| 11 | /// <summary> |
| 12 | /// Extensions methods for adding Burn services. |
| 13 | /// </summary> |
| 14 | public static class WixToolsetCoreServiceProviderExtensions |
| 15 | { |
| 16 | /// <summary> |
| 17 | /// Adds Burn Services. |
| 18 | /// </summary> |
| 19 | /// <param name="coreProvider"></param> |
| 20 | /// <returns></returns> |
| 21 | public static IWixToolsetCoreServiceProvider AddBundleBackend(this IWixToolsetCoreServiceProvider coreProvider) |
| 22 | { |
| 23 | AddServices(coreProvider); |
| 24 | |
| 25 | var extensionManager = coreProvider.GetService<IExtensionManager>(); |
| 26 | extensionManager.Add(typeof(BurnExtensionFactory).Assembly); |
| 27 | |
| 28 | return coreProvider; |
| 29 | } |
| 30 | |
| 31 | private static void AddServices(IWixToolsetCoreServiceProvider coreProvider) |
| 32 | { |
| 33 | // Singletons. |
| 34 | coreProvider.AddService((provider, singletons) => AddSingleton<IInternalBurnBackendHelper>(singletons, new BurnBackendHelper(provider))); |
| 35 | coreProvider.AddService((provider, singletons) => AddSingleton<IPayloadHarvester>(singletons, new PayloadHarvester())); |
| 36 | coreProvider.AddService((provider, singletons) => AddSingleton<IBurnBackendHelper>(singletons, provider.GetService<IInternalBurnBackendHelper>())); |
| 37 | } |
| 38 | |
| 39 | private static T AddSingleton<T>(Dictionary<Type, object> singletons, T service) where T : class |
| 40 | { |
| 41 | singletons.Add(typeof(T), service); |
| 42 | return service; |
| 43 | } |
| 44 | } |
| 45 | } |