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

Commit d72ff9b

Browse files
committed
Use IAsyncServiceProvider rather than delegate
Use IAsyncServiceProvider from the Microsoft.VisualStudio.Shell.Immutable.14.0 assembly.
1 parent c13c597 commit d72ff9b

File tree

9 files changed

+52
-16
lines changed

9 files changed

+52
-16
lines changed

src/GitHub.TeamFoundation.14/GitHub.TeamFoundation.14.csproj

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@
7979
<HintPath>..\..\packages\Microsoft.VisualStudio.ComponentModelHost.14.0.25424\lib\net45\Microsoft.VisualStudio.ComponentModelHost.dll</HintPath>
8080
<Private>True</Private>
8181
</Reference>
82+
<Reference Include="Microsoft.VisualStudio.OLE.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
83+
<HintPath>..\..\packages\Microsoft.VisualStudio.OLE.Interop.7.10.6070\lib\Microsoft.VisualStudio.OLE.Interop.dll</HintPath>
84+
<Private>True</Private>
85+
</Reference>
8286
<Reference Include="Microsoft.VisualStudio.Shell.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
8387
<HintPath>..\..\packages\Microsoft.VisualStudio.Shell.14.0.14.3.25407\lib\Microsoft.VisualStudio.Shell.14.0.dll</HintPath>
8488
<Private>True</Private>
@@ -87,6 +91,15 @@
8791
<HintPath>..\..\packages\Microsoft.VisualStudio.Shell.Immutable.10.0.10.0.30319\lib\net40\Microsoft.VisualStudio.Shell.Immutable.10.0.dll</HintPath>
8892
<Private>True</Private>
8993
</Reference>
94+
<Reference Include="Microsoft.VisualStudio.Shell.Immutable.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
95+
<HintPath>..\..\packages\Microsoft.VisualStudio.Shell.Immutable.11.0.11.0.50727\lib\net45\Microsoft.VisualStudio.Shell.Immutable.11.0.dll</HintPath>
96+
<Private>True</Private>
97+
</Reference>
98+
<Reference Include="Microsoft.VisualStudio.Shell.Immutable.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
99+
<HintPath>..\..\packages\Microsoft.VisualStudio.Shell.Immutable.14.0.14.3.25407\lib\net45\Microsoft.VisualStudio.Shell.Immutable.14.0.dll</HintPath>
100+
<Private>True</Private>
101+
<Aliases>SI14</Aliases>
102+
</Reference>
90103
<Reference Include="Microsoft.VisualStudio.Shell.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
91104
<HintPath>..\..\packages\Microsoft.VisualStudio.Shell.Interop.7.10.6071\lib\Microsoft.VisualStudio.Shell.Interop.dll</HintPath>
92105
<Private>True</Private>
@@ -95,6 +108,10 @@
95108
<HintPath>..\..\packages\Microsoft.VisualStudio.Shell.Interop.8.0.8.0.50727\lib\Microsoft.VisualStudio.Shell.Interop.8.0.dll</HintPath>
96109
<Private>True</Private>
97110
</Reference>
111+
<Reference Include="Microsoft.VisualStudio.TextManager.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
112+
<HintPath>..\..\packages\Microsoft.VisualStudio.TextManager.Interop.7.10.6070\lib\Microsoft.VisualStudio.TextManager.Interop.dll</HintPath>
113+
<Private>True</Private>
114+
</Reference>
98115
<Reference Include="PresentationCore" />
99116
<Reference Include="PresentationFramework" />
100117
<Reference Include="Serilog, Version=2.0.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">

src/GitHub.TeamFoundation.14/Services/VSGitExt.cs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
extern alias SI14;
12
using System;
23
using System.Linq;
34
using System.Threading.Tasks;
@@ -9,6 +10,8 @@
910
using GitHub.TeamFoundation.Services;
1011
using Serilog;
1112
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
13+
using Task = System.Threading.Tasks.Task;
14+
using IAsyncServiceProvider = SI14::Microsoft.VisualStudio.Shell.IAsyncServiceProvider;
1215

1316
namespace GitHub.VisualStudio.Base
1417
{
@@ -23,22 +26,22 @@ public class VSGitExt : IVSGitExt
2326
{
2427
static readonly ILogger log = LogManager.ForContext<VSGitExt>();
2528

26-
readonly Func<Type, Task<object>> getServiceAsync;
29+
readonly IAsyncServiceProvider asyncServiceProvider;
2730
readonly ILocalRepositoryModelFactory repositoryFactory;
2831
readonly object refreshLock = new object();
2932

3033
IGitExt gitService;
3134
IReadOnlyList<ILocalRepositoryModel> activeRepositories;
3235

3336
[ImportingConstructor]
34-
public VSGitExt(Func<Type, Task<object>> getServiceAsync)
35-
: this(getServiceAsync, new VSUIContextFactory(), new LocalRepositoryModelFactory())
37+
public VSGitExt(IAsyncServiceProvider asyncServiceProvider)
38+
: this(asyncServiceProvider, new VSUIContextFactory(), new LocalRepositoryModelFactory())
3639
{
3740
}
3841

39-
public VSGitExt(Func<Type, Task<object>> getServiceAsync, IVSUIContextFactory factory, ILocalRepositoryModelFactory repositoryFactory)
42+
public VSGitExt(IAsyncServiceProvider asyncServiceProvider, IVSUIContextFactory factory, ILocalRepositoryModelFactory repositoryFactory)
4043
{
41-
this.getServiceAsync = getServiceAsync;
44+
this.asyncServiceProvider = asyncServiceProvider;
4245
this.repositoryFactory = repositoryFactory;
4346

4447
// Start with empty array until we have a chance to initialize.
@@ -52,7 +55,7 @@ public VSGitExt(Func<Type, Task<object>> getServiceAsync, IVSUIContextFactory fa
5255

5356
void Initialize()
5457
{
55-
PendingTasks = getServiceAsync(typeof(IGitExt)).ContinueWith(t =>
58+
PendingTasks = asyncServiceProvider.GetServiceAsync(typeof(IGitExt)).ContinueWith(t =>
5659
{
5760
gitService = (IGitExt)t.Result;
5861
if (gitService == null)

src/GitHub.TeamFoundation.14/packages.config

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
<package id="LibGit2Sharp" version="0.23.1" targetFramework="net461" />
44
<package id="LibGit2Sharp.NativeBinaries" version="1.0.164" targetFramework="net461" />
55
<package id="Microsoft.VisualStudio.ComponentModelHost" version="14.0.25424" targetFramework="net461" />
6+
<package id="Microsoft.VisualStudio.OLE.Interop" version="7.10.6070" targetFramework="net461" />
67
<package id="Microsoft.VisualStudio.Shell.14.0" version="14.3.25407" targetFramework="net461" />
78
<package id="Microsoft.VisualStudio.Shell.Immutable.10.0" version="10.0.30319" targetFramework="net461" />
9+
<package id="Microsoft.VisualStudio.Shell.Immutable.11.0" version="11.0.50727" targetFramework="net461" />
10+
<package id="Microsoft.VisualStudio.Shell.Immutable.14.0" version="14.3.25407" targetFramework="net461" />
811
<package id="Microsoft.VisualStudio.Shell.Interop" version="7.10.6071" targetFramework="net461" />
912
<package id="Microsoft.VisualStudio.Shell.Interop.8.0" version="8.0.50727" targetFramework="net461" />
13+
<package id="Microsoft.VisualStudio.TextManager.Interop" version="7.10.6070" targetFramework="net461" />
1014
<package id="Rx-Core" version="2.2.5-custom" targetFramework="net45" />
1115
<package id="Rx-Interfaces" version="2.2.5-custom" targetFramework="net45" />
1216
<package id="Serilog" version="2.5.0" targetFramework="net461" />

src/GitHub.TeamFoundation.15/GitHub.TeamFoundation.15.csproj

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@
9595
<HintPath>..\..\packages\Microsoft.VisualStudio.Shell.Framework.15.4.27004\lib\net45\Microsoft.VisualStudio.Shell.Framework.dll</HintPath>
9696
<Private>True</Private>
9797
</Reference>
98+
<Reference Include="Microsoft.VisualStudio.Shell.Immutable.11.0, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
99+
<HintPath>..\..\packages\Microsoft.VisualStudio.Shell.Immutable.11.0.11.0.50727\lib\net45\Microsoft.VisualStudio.Shell.Immutable.11.0.dll</HintPath>
100+
<Private>True</Private>
101+
</Reference>
102+
<Reference Include="Microsoft.VisualStudio.Shell.Immutable.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
103+
<HintPath>..\..\packages\Microsoft.VisualStudio.Shell.Immutable.14.0.14.3.25407\lib\net45\Microsoft.VisualStudio.Shell.Immutable.14.0.dll</HintPath>
104+
<Private>True</Private>
105+
<Aliases>SI14</Aliases>
106+
</Reference>
98107
<Reference Include="Microsoft.VisualStudio.Shell.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
99108
<HintPath>..\..\packages\Microsoft.VisualStudio.Shell.Interop.7.10.6071\lib\Microsoft.VisualStudio.Shell.Interop.dll</HintPath>
100109
<Private>True</Private>

src/GitHub.TeamFoundation.15/packages.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
<package id="Microsoft.VisualStudio.SDK.EmbedInteropTypes" version="15.0.12" targetFramework="net461" />
99
<package id="Microsoft.VisualStudio.Shell.15.0" version="15.4.27004" targetFramework="net461" />
1010
<package id="Microsoft.VisualStudio.Shell.Framework" version="15.4.27004" targetFramework="net461" />
11+
<package id="Microsoft.VisualStudio.Shell.Immutable.11.0" version="11.0.50727" targetFramework="net461" />
12+
<package id="Microsoft.VisualStudio.Shell.Immutable.14.0" version="14.3.25407" targetFramework="net461" />
1113
<package id="Microsoft.VisualStudio.Shell.Interop" version="7.10.6071" targetFramework="net461" />
1214
<package id="Microsoft.VisualStudio.Shell.Interop.15.3.DesignTime" version="15.0.26606" targetFramework="net461" />
1315
<package id="Microsoft.VisualStudio.Shell.Interop.8.0" version="8.0.50727" targetFramework="net461" />

src/GitHub.VisualStudio/Services/VSGitExtFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ public static IVSGitExt Create(int vsVersion, IAsyncServiceProvider sp)
2828
switch (vsVersion)
2929
{
3030
case 14:
31-
return Create(() => new VSGitExt14(sp.GetServiceAsync));
31+
return Create(() => new VSGitExt14(sp));
3232
case 15:
33-
return Create(() => new VSGitExt15(sp.GetServiceAsync));
33+
return Create(() => new VSGitExt15(sp));
3434
default:
3535
log.Error("There is no IVSGitExt implementation for DTE version {Version}", vsVersion);
3636
return null;

test/UnitTests/GitHub.TeamFoundation/VSGitExtTests.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using System.Threading;
34
using System.ComponentModel;
45
using System.Collections.Generic;
@@ -9,8 +10,8 @@
910
using NUnit.Framework;
1011
using NSubstitute;
1112
using Microsoft.VisualStudio.TeamFoundation.Git.Extensibility;
12-
using System.Threading.Tasks;
13-
using System.Linq;
13+
using Microsoft.VisualStudio.Shell;
14+
using Task = System.Threading.Tasks.Task;
1415

1516
public class VSGitExtTests
1617
{
@@ -216,16 +217,11 @@ static VSGitExt CreateVSGitExt(IVSUIContext context = null, IGitExt gitExt = nul
216217
var contextGuid = new Guid(Guids.GitSccProviderId);
217218
factory.GetUIContext(contextGuid).Returns(context);
218219
sp.GetServiceAsync(typeof(IGitExt)).Returns(gitExt);
219-
var vsGitExt = new VSGitExt(sp.GetServiceAsync, factory, repoFactory);
220+
var vsGitExt = new VSGitExt(sp, factory, repoFactory);
220221
vsGitExt.PendingTasks.Wait();
221222
return vsGitExt;
222223
}
223224

224-
public interface IAsyncServiceProvider
225-
{
226-
Task<object> GetServiceAsync(Type serviceType);
227-
}
228-
229225
static IGitExt CreateGitExt(params string[] repositoryPaths)
230226
{
231227
var gitExt = Substitute.For<IGitExt>();

test/UnitTests/UnitTests.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,10 @@
107107
<HintPath>..\..\packages\Microsoft.VisualStudio.Shell.Immutable.12.0.12.0.21003\lib\net45\Microsoft.VisualStudio.Shell.Immutable.12.0.dll</HintPath>
108108
<Private>True</Private>
109109
</Reference>
110+
<Reference Include="Microsoft.VisualStudio.Shell.Immutable.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
111+
<HintPath>..\..\packages\Microsoft.VisualStudio.Shell.Immutable.14.0.14.3.25407\lib\net45\Microsoft.VisualStudio.Shell.Immutable.14.0.dll</HintPath>
112+
<Private>True</Private>
113+
</Reference>
110114
<Reference Include="Microsoft.VisualStudio.Shell.Interop, Version=7.1.40304.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
111115
<HintPath>..\..\packages\Microsoft.VisualStudio.Shell.Interop.7.10.6071\lib\Microsoft.VisualStudio.Shell.Interop.dll</HintPath>
112116
<Private>True</Private>

test/UnitTests/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<package id="Microsoft.VisualStudio.Shell.Immutable.10.0" version="10.0.30319" targetFramework="net461" />
1313
<package id="Microsoft.VisualStudio.Shell.Immutable.11.0" version="11.0.50727" targetFramework="net461" />
1414
<package id="Microsoft.VisualStudio.Shell.Immutable.12.0" version="12.0.21003" targetFramework="net461" />
15+
<package id="Microsoft.VisualStudio.Shell.Immutable.14.0" version="14.3.25407" targetFramework="net461" />
1516
<package id="Microsoft.VisualStudio.Shell.Interop" version="7.10.6071" targetFramework="net461" />
1617
<package id="Microsoft.VisualStudio.Shell.Interop.10.0" version="10.0.30319" targetFramework="net461" />
1718
<package id="Microsoft.VisualStudio.Shell.Interop.11.0" version="11.0.61030" targetFramework="net461" />

0 commit comments

Comments
 (0)