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

Commit 719e624

Browse files
committed
Move all construction logic into VSGitExtFactory.Create
1 parent b98cc52 commit 719e624

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
using Microsoft.VisualStudio;
1919
using Microsoft.VisualStudio.Shell;
2020
using Microsoft.VisualStudio.Shell.Interop;
21-
using EnvDTE;
2221
using Octokit;
2322
using Serilog;
2423
using Task = System.Threading.Tasks.Task;
@@ -262,8 +261,7 @@ async Task<object> CreateService(IAsyncServiceContainer container, CancellationT
262261
}
263262
else if (serviceType == typeof(IVSGitExt))
264263
{
265-
var dte = await GetServiceAsync(typeof(DTE)) as DTE;
266-
return VSGitExtFactory.Create(dte.Version, this);
264+
return await VSGitExtFactory.Create(this);
267265
}
268266
else if (serviceType == typeof(IGitHubToolWindowManager))
269267
{

src/GitHub.VisualStudio/Services/VSGitExtFactory.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
extern alias TF15;
33

44
using System;
5+
using System.Threading.Tasks;
56
using System.ComponentModel.Composition;
67
using GitHub.Logging;
78
using Serilog;
9+
using EnvDTE;
10+
using Microsoft.VisualStudio.Shell;
811
using VSGitExt14 = TF14.GitHub.VisualStudio.Base.VSGitExt;
912
using VSGitExt15 = TF15.GitHub.VisualStudio.Base.VSGitExt;
10-
using Microsoft.VisualStudio.Shell;
1113

1214
namespace GitHub.Services
1315
{
@@ -27,17 +29,19 @@ public VSGitExtFactory(IGitHubServiceProvider serviceProvider)
2729
[Export(typeof(IVSGitExt))]
2830
public IVSGitExt VSGitExt => serviceProvider.GetService<IVSGitExt>();
2931

30-
public static IVSGitExt Create(string dteVersion, IAsyncServiceProvider sp)
32+
public async static Task<IVSGitExt> Create(IAsyncServiceProvider sp)
3133
{
34+
var dte = await sp.GetServiceAsync(typeof(DTE)) as DTE;
35+
3236
// DTE.Version always ends with ".0" even for later minor versions.
33-
switch (dteVersion)
37+
switch (dte.Version)
3438
{
3539
case "14.0":
3640
return new Lazy<IVSGitExt>(() => new VSGitExt14(sp.GetServiceAsync)).Value;
3741
case "15.0":
3842
return new Lazy<IVSGitExt>(() => new VSGitExt15(sp.GetServiceAsync)).Value;
3943
default:
40-
log.Error("There is no IVSGitExt implementation for DTE version {Version}", dteVersion);
44+
log.Error("There is no IVSGitExt implementation for DTE version {Version}", dte.Version);
4145
return null;
4246
}
4347
}

0 commit comments

Comments
 (0)