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

Commit c0e369c

Browse files
committed
Pass IServiceProvider not IAsyncServiceProvider
There are assemblies with exactly the same IAsyncServiceProvider namespace + name. Change to use IServiceProvider instead to avoid having to use assembly aliases. These were getting more complication with the introduction of Visual Studio 2019 support.
1 parent 0c28510 commit c0e369c

File tree

3 files changed

+18
-20
lines changed

3 files changed

+18
-20
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,26 @@ public class VSGitExt : IVSGitExt
2626
{
2727
static readonly ILogger log = LogManager.ForContext<VSGitExt>();
2828

29-
readonly IAsyncServiceProvider asyncServiceProvider;
29+
readonly IServiceProvider serviceProvider;
3030
readonly ILocalRepositoryModelFactory repositoryFactory;
3131
readonly object refreshLock = new object();
3232

3333
IGitExt gitService;
3434
IReadOnlyList<ILocalRepositoryModel> activeRepositories;
3535

36-
public VSGitExt(IAsyncServiceProvider asyncServiceProvider)
37-
: this(asyncServiceProvider, new VSUIContextFactory(), new LocalRepositoryModelFactory(), ThreadHelper.JoinableTaskContext)
36+
public VSGitExt(IServiceProvider serviceProvider)
37+
: this(serviceProvider, new VSUIContextFactory(), new LocalRepositoryModelFactory(), ThreadHelper.JoinableTaskContext)
3838
{
3939
}
4040

41-
public VSGitExt(IAsyncServiceProvider asyncServiceProvider, IVSUIContextFactory factory, ILocalRepositoryModelFactory repositoryFactory,
41+
public VSGitExt(IServiceProvider serviceProvider, IVSUIContextFactory factory, ILocalRepositoryModelFactory repositoryFactory,
4242
JoinableTaskContext joinableTaskContext)
4343
{
4444
JoinableTaskCollection = joinableTaskContext.CreateCollection();
4545
JoinableTaskCollection.DisplayName = nameof(VSGitExt);
4646
JoinableTaskFactory = joinableTaskContext.CreateFactory(JoinableTaskCollection);
4747

48-
this.asyncServiceProvider = asyncServiceProvider;
48+
this.serviceProvider = serviceProvider;
4949
this.repositoryFactory = repositoryFactory;
5050

5151
// Start with empty array until we have a chance to initialize.
@@ -133,10 +133,9 @@ public void JoinTillEmpty()
133133
async Task<T> GetServiceAsync<T>()
134134
{
135135
await JoinableTaskFactory.SwitchToMainThreadAsync();
136-
return (T)await asyncServiceProvider.GetServiceAsync(typeof(T));
136+
return (T)serviceProvider.GetService(typeof(T));
137137
}
138138

139-
140139
public event Action ActiveRepositoriesChanged;
141140

142141
JoinableTaskCollection JoinableTaskCollection { get; }

src/GitHub.VisualStudio/Services/VSGitExtFactory.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System;
55
using GitHub.Logging;
66
using Serilog;
7-
using Microsoft.VisualStudio.Shell;
87
using VSGitExt14 = TF14.GitHub.VisualStudio.Base.VSGitExt;
98
using VSGitExt15 = TF15.GitHub.VisualStudio.Base.VSGitExt;
109

@@ -15,23 +14,23 @@ public class VSGitExtFactory
1514
static readonly ILogger log = LogManager.ForContext<VSGitExtFactory>();
1615

1716
readonly int vsVersion;
18-
readonly IAsyncServiceProvider asyncServiceProvider;
17+
readonly IServiceProvider serviceProvider;
1918

20-
public VSGitExtFactory(int vsVersion, IAsyncServiceProvider asyncServiceProvider)
19+
public VSGitExtFactory(int vsVersion, IServiceProvider serviceProvider)
2120
{
2221
this.vsVersion = vsVersion;
23-
this.asyncServiceProvider = asyncServiceProvider;
22+
this.serviceProvider = serviceProvider;
2423
}
2524

2625
public IVSGitExt Create()
2726
{
2827
switch (vsVersion)
2928
{
3029
case 14:
31-
return Create(() => new VSGitExt14(asyncServiceProvider));
30+
return Create(() => new VSGitExt14(serviceProvider));
3231
case 15:
3332
case 16:
34-
return Create(() => new VSGitExt15(asyncServiceProvider));
33+
return Create(() => new VSGitExt15(serviceProvider));
3534
default:
3635
log.Error("There is no IVSGitExt implementation for DTE version {Version}", vsVersion);
3736
return null;

test/GitHub.TeamFoundation.UnitTests/VSGitExtTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ public class TheConstructor : TestBaseClass
2525
public void GetServiceIGitExt_WhenGitSccProviderIsActive(bool isActive, string contextGuidString, int expectCalls)
2626
{
2727
var context = CreateVSUIContext(isActive);
28-
var sp = Substitute.For<IAsyncServiceProvider>();
28+
var sp = Substitute.For<IServiceProvider>();
2929

3030
var target = CreateVSGitExt(context, sp: sp, contextGuidString: contextGuidString);
3131

32-
sp.Received(expectCalls).GetServiceAsync(typeof(IGitExt));
32+
sp.Received(expectCalls).GetService(typeof(IGitExt));
3333
}
3434

3535
[TestCase(true, 1)]
3636
[TestCase(false, 0)]
3737
public void GetServiceIGitExt_WhenUIContextChanged(bool activated, int expectCalls)
3838
{
3939
var context = CreateVSUIContext(false);
40-
var sp = Substitute.For<IAsyncServiceProvider>();
40+
var sp = Substitute.For<IServiceProvider>();
4141
var target = CreateVSGitExt(context, sp: sp);
4242

4343
context.IsActive = activated;
4444
target.JoinTillEmpty();
4545

46-
sp.Received(expectCalls).GetServiceAsync(typeof(IGitExt));
46+
sp.Received(expectCalls).GetService(typeof(IGitExt));
4747
}
4848

4949
[Test]
@@ -210,18 +210,18 @@ static IReadOnlyList<IGitRepositoryInfo> CreateActiveRepositories(params string[
210210
return repositories.AsReadOnly();
211211
}
212212

213-
static VSGitExt CreateVSGitExt(IVSUIContext context = null, IGitExt gitExt = null, IAsyncServiceProvider sp = null,
213+
static VSGitExt CreateVSGitExt(IVSUIContext context = null, IGitExt gitExt = null, IServiceProvider sp = null,
214214
ILocalRepositoryModelFactory repoFactory = null, JoinableTaskContext joinableTaskContext = null, string contextGuidString = null)
215215
{
216216
context = context ?? CreateVSUIContext(true);
217217
gitExt = gitExt ?? CreateGitExt();
218218
var contextGuid = new Guid(contextGuidString ?? Guids.GitSccProviderId);
219-
sp = sp ?? Substitute.For<IAsyncServiceProvider>();
219+
sp = sp ?? Substitute.For<IServiceProvider>();
220220
repoFactory = repoFactory ?? Substitute.For<ILocalRepositoryModelFactory>();
221221
joinableTaskContext = joinableTaskContext ?? new JoinableTaskContext();
222222
var factory = Substitute.For<IVSUIContextFactory>();
223223
factory.GetUIContext(contextGuid).Returns(context);
224-
sp.GetServiceAsync(typeof(IGitExt)).Returns(gitExt);
224+
sp.GetService(typeof(IGitExt)).Returns(gitExt);
225225
var vsGitExt = new VSGitExt(sp, factory, repoFactory, joinableTaskContext);
226226
vsGitExt.JoinTillEmpty();
227227
return vsGitExt;

0 commit comments

Comments
 (0)