From 1d6ff8af3c423ee4622185edc986ae5caad6b122 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 26 Dec 2017 15:11:40 -0800 Subject: Standardize creation of public objects in move towards interfaces --- src/WixToolset.Core/Linker.cs | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'src/WixToolset.Core/Linker.cs') diff --git a/src/WixToolset.Core/Linker.cs b/src/WixToolset.Core/Linker.cs index 93f50efa..79ddd30a 100644 --- a/src/WixToolset.Core/Linker.cs +++ b/src/WixToolset.Core/Linker.cs @@ -12,6 +12,7 @@ namespace WixToolset.Core using WixToolset.Data; using WixToolset.Data.Tuples; using WixToolset.Extensibility; + using WixToolset.Extensibility.Services; using WixToolset.Link; /// @@ -27,14 +28,17 @@ namespace WixToolset.Core /// /// Creates a linker. /// - public Linker() + public Linker(IServiceProvider serviceProvider) { + this.ServiceProvider = serviceProvider; this.sectionIdOnRows = true; // TODO: what is the correct value for this? //this.extensionData = new List(); //this.inspectorExtensions = new List(); } + private IServiceProvider ServiceProvider { get; } + private ILinkContext Context { get; set; } /// @@ -49,11 +53,13 @@ namespace WixToolset.Core /// The option to show pedantic messages. public bool ShowPedanticMessages { get; set; } - /// - /// Gets or sets the Wix variable resolver. - /// - /// The Wix variable resolver. - //internal IBindVariableResolver WixVariableResolver { get; set; } + public OutputType OutputType { get; set; } + + public IEnumerable Intermediates { get; set; } + + public IEnumerable Libraries { get; set; } + + public ITupleDefinitionCreator TupleDefinitionCreator { get; set; } /// /// Links a collection of sections into an output. @@ -61,16 +67,26 @@ namespace WixToolset.Core /// The collection of sections to link together. /// Expected output type, based on output file extension provided to the linker. /// Output object from the linking. - public Intermediate Link(ILinkContext context) + public Intermediate Execute() { - this.Context = context ?? throw new ArgumentNullException(nameof(context)); + var extensionManager = this.ServiceProvider.GetService(); + + var creator = this.TupleDefinitionCreator ?? this.ServiceProvider.GetService(); + + this.Context = this.ServiceProvider.GetService(); + this.Context.Messaging = this.ServiceProvider.GetService(); + this.Context.Extensions = extensionManager.Create(); + this.Context.ExtensionData = extensionManager.Create(); + this.Context.ExpectedOutputType = this.OutputType; + this.Context.Intermediates = this.Intermediates.Union(this.Libraries).ToList(); + this.Context.TupleDefinitionCreator = creator; var sections = this.Context.Intermediates.SelectMany(i => i.Sections).ToList(); // Add sections from the extensions with data. - foreach (var data in context.ExtensionData) + foreach (var data in this.Context.ExtensionData) { - var library = data.GetLibrary(context.TupleDefinitionCreator); + var library = data.GetLibrary(this.Context.TupleDefinitionCreator); if (library != null) { -- cgit v1.2.3-55-g6feb