зеркало из https://github.com/github/VisualStudio.git
Use IGitHubServiceProvider as global provider
Register IGitHubServiceProvider with singleton Service class to use as global provider.
This commit is contained in:
Родитель
d7b6984a41
Коммит
1e44afd8ba
|
@ -85,23 +85,14 @@ namespace GitHub.VisualStudio
|
|||
|
||||
var gitHubServiceProvider = new MyGitHubServiceProvider(compositionContainer);
|
||||
compositionContainer.ComposeExportedValue<IGitHubServiceProvider>(gitHubServiceProvider);
|
||||
Services.UnitTestServiceProvider = gitHubServiceProvider; // Use gitHubServiceProvider as global provider
|
||||
|
||||
var loginManager = CreateLoginManager(compositionContainer);
|
||||
compositionContainer.ComposeExportedValue<ILoginManager>(loginManager);
|
||||
|
||||
// HACK: Stop ViewLocator from attempting to fetch a global service
|
||||
var viewViewModelFactory = compositionContainer.GetExportedValue<IViewViewModelFactory>();
|
||||
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<IKeychain>();
|
||||
|
@ -192,6 +183,11 @@ namespace GitHub.VisualStudio
|
|||
|
||||
public object GetService(Type serviceType)
|
||||
{
|
||||
if (serviceType == typeof(IGitHubServiceProvider))
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
return serviceProvider.GetService(serviceType);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче