Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 1205790

Browse files
committed
Remove dependency on IComponentModel
Retrieve IVSGitExt and IPullRequestSessionManager via GitHubServiceProvider.
1 parent 66fbbaa commit 1205790

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

src/GitHub.InlineReviews/PullRequestStatusBarPackage.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System;
22
using System.Threading;
33
using System.Runtime.InteropServices;
4-
using Microsoft.VisualStudio.Shell;
5-
using Microsoft.VisualStudio.ComponentModelHost;
64
using GitHub.Helpers;
75
using GitHub.Services;
86
using GitHub.VisualStudio;
97
using GitHub.InlineReviews.Services;
8+
using Microsoft.VisualStudio.Shell;
109
using Task = System.Threading.Tasks.Task;
1110

1211
namespace GitHub.InlineReviews
@@ -23,13 +22,10 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
2322
{
2423
var usageTracker = (IUsageTracker)await GetServiceAsync(typeof(IUsageTracker));
2524
var serviceProvider = (IGitHubServiceProvider)await GetServiceAsync(typeof(IGitHubServiceProvider));
26-
var componentModel = (IComponentModel)await GetServiceAsync(typeof(SComponentModel));
27-
var pullRequestSessionManager = componentModel.DefaultExportProvider.GetExport<IPullRequestSessionManager>();
2825

2926
await ThreadingHelper.SwitchToMainThreadAsync();
30-
var gitExt = componentModel.DefaultExportProvider.GetExportedValue<IVSGitExt>();
31-
32-
new PullRequestStatusBarManager(gitExt, pullRequestSessionManager, usageTracker, serviceProvider);
27+
var gitExt = serviceProvider.GetService<IVSGitExt>();
28+
new PullRequestStatusBarManager(gitExt, usageTracker, serviceProvider);
3329
}
3430
}
3531
}

src/GitHub.InlineReviews/Services/PullRequestStatusBarManager.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ public class PullRequestStatusBarManager
2424
const string StatusBarPartName = "PART_SccStatusBarHost";
2525

2626
readonly IVSGitExt gitExt;
27-
readonly Lazy<IPullRequestSessionManager> pullRequestSessionManager;
2827
readonly IUsageTracker usageTracker;
2928
readonly IGitHubServiceProvider serviceProvider;
3029

30+
IPullRequestSessionManager pullRequestSessionManager;
31+
3132
[ImportingConstructor]
32-
public PullRequestStatusBarManager(IVSGitExt gitExt, Lazy<IPullRequestSessionManager> pullRequestSessionManager,
33-
IUsageTracker usageTracker, IGitHubServiceProvider serviceProvider)
33+
public PullRequestStatusBarManager(IVSGitExt gitExt, IUsageTracker usageTracker, IGitHubServiceProvider serviceProvider)
3434
{
3535
this.gitExt = gitExt;
36-
this.pullRequestSessionManager = pullRequestSessionManager;
3736
this.usageTracker = usageTracker;
3837
this.serviceProvider = serviceProvider;
3938

@@ -56,8 +55,11 @@ async Task StartShowingStatus()
5655
{
5756
await ThreadingHelper.SwitchToMainThreadAsync(); // Switch from VSGitExt to Main thread
5857

58+
// Create just in time on Main thread.
59+
pullRequestSessionManager = serviceProvider.GetService<IPullRequestSessionManager>();
60+
5961
RefreshCurrentSession();
60-
pullRequestSessionManager.Value.PropertyChanged += PullRequestSessionManager_PropertyChanged;
62+
pullRequestSessionManager.PropertyChanged += PullRequestSessionManager_PropertyChanged;
6163
}
6264
catch (Exception e)
6365
{
@@ -75,7 +77,7 @@ void PullRequestSessionManager_PropertyChanged(object sender, PropertyChangedEve
7577

7678
void RefreshCurrentSession()
7779
{
78-
var pullRequest = pullRequestSessionManager.Value.CurrentSession?.PullRequest;
80+
var pullRequest = pullRequestSessionManager.CurrentSession?.PullRequest;
7981
var viewModel = pullRequest != null ? CreatePullRequestStatusViewModel(pullRequest) : null;
8082
ShowStatus(viewModel);
8183
}

0 commit comments

Comments
 (0)