Use IGitHubServiceProvider as global provider

Register IGitHubServiceProvider with singleton Service class to use as global provider.
This commit is contained in:
Jamie Cansdale 2019-05-28 12:22:18 +01:00
Родитель d7b6984a41
Коммит 1e44afd8ba
1 изменённых файлов: 6 добавлений и 10 удалений

Просмотреть файл

@ -85,23 +85,14 @@ namespace GitHub.VisualStudio
var gitHubServiceProvider = new MyGitHubServiceProvider(compositionContainer); var gitHubServiceProvider = new MyGitHubServiceProvider(compositionContainer);
compositionContainer.ComposeExportedValue<IGitHubServiceProvider>(gitHubServiceProvider); compositionContainer.ComposeExportedValue<IGitHubServiceProvider>(gitHubServiceProvider);
Services.UnitTestServiceProvider = gitHubServiceProvider; // Use gitHubServiceProvider as global provider
var loginManager = CreateLoginManager(compositionContainer); var loginManager = CreateLoginManager(compositionContainer);
compositionContainer.ComposeExportedValue<ILoginManager>(loginManager); compositionContainer.ComposeExportedValue<ILoginManager>(loginManager);
// HACK: Stop ViewLocator from attempting to fetch a global service
var viewViewModelFactory = compositionContainer.GetExportedValue<IViewViewModelFactory>();
InitializeViewLocator(viewViewModelFactory);
return compositionContainer; 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) static LoginManager CreateLoginManager(CompositionContainer compositionContainer)
{ {
var keychain = compositionContainer.GetExportedValue<IKeychain>(); var keychain = compositionContainer.GetExportedValue<IKeychain>();
@ -192,6 +183,11 @@ namespace GitHub.VisualStudio
public object GetService(Type serviceType) public object GetService(Type serviceType)
{ {
if (serviceType == typeof(IGitHubServiceProvider))
{
return this;
}
return serviceProvider.GetService(serviceType); return serviceProvider.GetService(serviceType);
} }