From e208f7683a033f2aed0df0b99744801874b31da7 Mon Sep 17 00:00:00 2001 From: Gary Ewan Park Date: Fri, 10 Nov 2023 20:24:39 +0000 Subject: [PATCH] (maint) Refactor IoC registration To only create the client when it is actually required. --- src/GitReleaseManager.Cli/Program.cs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/GitReleaseManager.Cli/Program.cs b/src/GitReleaseManager.Cli/Program.cs index f89fc72d..dc44e89c 100644 --- a/src/GitReleaseManager.Cli/Program.cs +++ b/src/GitReleaseManager.Cli/Program.cs @@ -202,17 +202,15 @@ private static void RegisterVcsProvider(BaseVcsOptions vcsOptions, IServiceColle Log.Information("Using {Provider} as VCS Provider", vcsOptions.Provider); if (vcsOptions.Provider == VcsProvider.GitLab) { - var gitlabClient = new GitLabClient("https://gitlab.com", vcsOptions.Token); serviceCollection - .AddSingleton() - .AddSingleton(gitlabClient); + .AddSingleton((_) => new GitLabClient("https://gitlab.com", vcsOptions.Token)) + .AddSingleton(); } else { // default to Github - var gitHubClient = new GitHubClient(new ProductHeaderValue("GitReleaseManager")) { Credentials = new Credentials(vcsOptions.Token) }; serviceCollection - .AddSingleton(gitHubClient) + .AddSingleton((_) => new GitHubClient(new ProductHeaderValue("GitReleaseManager")) { Credentials = new Credentials(vcsOptions.Token) }) .AddSingleton(); } }