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

Commit cbc3c0d

Browse files
committed
Lazy load ITwoFactorChallengeHandler in LoginManager.
So that `GitHub.App` is only loaded when actually needed.
1 parent 0232915 commit cbc3c0d

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/GitHub.Api/LoginManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public class LoginManager : ILoginManager
1414
{
1515
readonly string[] scopes = { "user", "repo", "gist", "write:public_key" };
1616
readonly IKeychain keychain;
17-
readonly ITwoFactorChallengeHandler twoFactorChallengeHandler;
17+
readonly Lazy<ITwoFactorChallengeHandler> twoFactorChallengeHandler;
1818
readonly string clientId;
1919
readonly string clientSecret;
2020
readonly string authorizationNote;
@@ -31,7 +31,7 @@ public class LoginManager : ILoginManager
3131
/// <param name="fingerprint">The machine fingerprint.</param>
3232
public LoginManager(
3333
IKeychain keychain,
34-
ITwoFactorChallengeHandler twoFactorChallengeHandler,
34+
Lazy<ITwoFactorChallengeHandler> twoFactorChallengeHandler,
3535
string clientId,
3636
string clientSecret,
3737
string authorizationNote = null,
@@ -194,7 +194,7 @@ async Task<ApplicationAuthorization> HandleTwoFactorAuthorization(
194194
{
195195
for (;;)
196196
{
197-
var challengeResult = await twoFactorChallengeHandler.HandleTwoFactorException(exception);
197+
var challengeResult = await twoFactorChallengeHandler.Value.HandleTwoFactorException(exception);
198198

199199
if (challengeResult == null)
200200
{
@@ -218,7 +218,7 @@ async Task<ApplicationAuthorization> HandleTwoFactorAuthorization(
218218
}
219219
catch (Exception e)
220220
{
221-
await twoFactorChallengeHandler.ChallengeFailed(e);
221+
await twoFactorChallengeHandler.Value.ChallengeFailed(e);
222222
await keychain.Delete(hostAddress).ConfigureAwait(false);
223223
throw;
224224
}

src/GitHub.VisualStudio/GitHubPackage.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.ComponentModel.Composition;
33
using System.Diagnostics;
4+
using System.Reflection;
45
using System.Runtime.InteropServices;
56
using System.Threading;
67
using System.Threading.Tasks;
@@ -211,11 +212,10 @@ async Task<object> CreateService(IAsyncServiceContainer container, CancellationT
211212
{
212213
var serviceProvider = await GetServiceAsync(typeof(IGitHubServiceProvider)) as IGitHubServiceProvider;
213214
var keychain = serviceProvider.GetService<IKeychain>();
214-
var twoFaHandler = serviceProvider.GetService<ITwoFactorChallengeHandler>();
215215

216216
return new LoginManager(
217217
keychain,
218-
twoFaHandler,
218+
new Lazy<ITwoFactorChallengeHandler>(() => serviceProvider.GetService<ITwoFactorChallengeHandler>()),
219219
ApiClientConfiguration.ClientId,
220220
ApiClientConfiguration.ClientSecret,
221221
ApiClientConfiguration.AuthorizationNote,

0 commit comments

Comments
 (0)