From 1e44afd8bad43bad093e003b4218144918ac0470 Mon Sep 17 00:00:00 2001 From: Jamie Cansdale Date: Tue, 28 May 2019 12:22:18 +0100 Subject: [PATCH] Use IGitHubServiceProvider as global provider Register IGitHubServiceProvider with singleton Service class to use as global provider. --- .../CompositionServices.cs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/GitHub.VisualStudio.16/CompositionServices.cs b/src/GitHub.VisualStudio.16/CompositionServices.cs index 44cec8b4e..168be3958 100644 --- a/src/GitHub.VisualStudio.16/CompositionServices.cs +++ b/src/GitHub.VisualStudio.16/CompositionServices.cs @@ -85,23 +85,14 @@ namespace GitHub.VisualStudio var gitHubServiceProvider = new MyGitHubServiceProvider(compositionContainer); compositionContainer.ComposeExportedValue(gitHubServiceProvider); + Services.UnitTestServiceProvider = gitHubServiceProvider; // Use gitHubServiceProvider as global provider var loginManager = CreateLoginManager(compositionContainer); compositionContainer.ComposeExportedValue(loginManager); - // HACK: Stop ViewLocator from attempting to fetch a global service - var viewViewModelFactory = compositionContainer.GetExportedValue(); - InitializeViewLocator(viewViewModelFactory); - return compositionContainer; } - static void InitializeViewLocator(IViewViewModelFactory viewViewModelFactory) - { - var factoryProviderFiled = typeof(ViewLocator).GetField("factoryProvider", BindingFlags.Static | BindingFlags.NonPublic); - factoryProviderFiled.SetValue(null, viewViewModelFactory); - } - static LoginManager CreateLoginManager(CompositionContainer compositionContainer) { var keychain = compositionContainer.GetExportedValue(); @@ -192,6 +183,11 @@ namespace GitHub.VisualStudio public object GetService(Type serviceType) { + if (serviceType == typeof(IGitHubServiceProvider)) + { + return this; + } + return serviceProvider.GetService(serviceType); }