From f195604266cb2b675d31c21df343e1f2ac8bdb0c Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 24 Oct 2018 21:04:19 -0700 Subject: Support passing IServiceProvider to IExtensionFactory's --- .../Example.Extension/ExampleExtensionFactory.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/test/Example.Extension/ExampleExtensionFactory.cs') diff --git a/src/test/Example.Extension/ExampleExtensionFactory.cs b/src/test/Example.Extension/ExampleExtensionFactory.cs index a081b758..ee9641a2 100644 --- a/src/test/Example.Extension/ExampleExtensionFactory.cs +++ b/src/test/Example.Extension/ExampleExtensionFactory.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 Example.Extension { @@ -9,16 +9,26 @@ namespace Example.Extension { private ExamplePreprocessorExtensionAndCommandLine preprocessorExtension; + public ExampleExtensionFactory(IServiceProvider serviceProvider) + { + this.ServiceProvider = serviceProvider; + } + + /// + /// This exists just to show it is possible to get a service provider to the extension factory. + /// + private IServiceProvider ServiceProvider { get; } + public bool TryCreateExtension(Type extensionType, out object extension) { if (extensionType == typeof(IExtensionCommandLine) || extensionType == typeof(IPreprocessorExtension)) { - if (preprocessorExtension == null) + if (this.preprocessorExtension == null) { - preprocessorExtension = new ExamplePreprocessorExtensionAndCommandLine(); + this.preprocessorExtension = new ExamplePreprocessorExtensionAndCommandLine(); } - extension = preprocessorExtension; + extension = this.preprocessorExtension; } else if (extensionType == typeof(ICompilerExtension)) { @@ -28,7 +38,7 @@ namespace Example.Extension { extension = new ExampleExtensionData(); } - else if (extensionType == typeof(IWindowsInstallerBackendExtension)) + else if (extensionType == typeof(IWindowsInstallerBackendBinderExtension)) { extension = new ExampleWindowsInstallerBackendExtension(); } @@ -36,7 +46,7 @@ namespace Example.Extension { extension = null; } - + return extension != null; } } -- cgit v1.2.3-55-g6feb