Skip to content

Commit e208f76

Browse files
committed
(maint) Refactor IoC registration
To only create the client when it is actually required.
1 parent a116eb4 commit e208f76

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/GitReleaseManager.Cli/Program.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,17 +202,15 @@ private static void RegisterVcsProvider(BaseVcsOptions vcsOptions, IServiceColle
202202
Log.Information("Using {Provider} as VCS Provider", vcsOptions.Provider);
203203
if (vcsOptions.Provider == VcsProvider.GitLab)
204204
{
205-
var gitlabClient = new GitLabClient("https://gitlab.com", vcsOptions.Token);
206205
serviceCollection
207-
.AddSingleton<IVcsProvider, GitLabProvider>()
208-
.AddSingleton<IGitLabClient>(gitlabClient);
206+
.AddSingleton<IGitLabClient>((_) => new GitLabClient("https://gitlab.com", vcsOptions.Token))
207+
.AddSingleton<IVcsProvider, GitLabProvider>();
209208
}
210209
else
211210
{
212211
// default to Github
213-
var gitHubClient = new GitHubClient(new ProductHeaderValue("GitReleaseManager")) { Credentials = new Credentials(vcsOptions.Token) };
214212
serviceCollection
215-
.AddSingleton<IGitHubClient>(gitHubClient)
213+
.AddSingleton<IGitHubClient>((_) => new GitHubClient(new ProductHeaderValue("GitReleaseManager")) { Credentials = new Credentials(vcsOptions.Token) })
216214
.AddSingleton<IVcsProvider, GitHubProvider>();
217215
}
218216
}

0 commit comments

Comments
 (0)