Skip to content

Commit

Permalink
(maint) Refactor IoC registration
Browse files Browse the repository at this point in the history
To only create the client when it is actually required.
  • Loading branch information
gep13 committed Nov 10, 2023
1 parent 7d9fcd9 commit 3e51f66
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/GitReleaseManager.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IVcsProvider, GitLabProvider>()
.AddSingleton<IGitLabClient>(gitlabClient);
.AddSingleton<IGitLabClient>((_) => new GitLabClient("https://gitlab.com", vcsOptions.Token))
.AddSingleton<IVcsProvider, GitLabProvider>();
}
else
{
// default to Github
var gitHubClient = new GitHubClient(new ProductHeaderValue("GitReleaseManager")) { Credentials = new Credentials(vcsOptions.Token) };
serviceCollection
.AddSingleton<IGitHubClient>(gitHubClient)
.AddSingleton<IGitHubClient>((_) => new GitHubClient(new ProductHeaderValue("GitReleaseManager")) { Credentials = new Credentials(vcsOptions.Token) })
.AddSingleton<IVcsProvider, GitHubProvider>();
}
}
Expand Down

0 comments on commit 3e51f66

Please sign in to comment.