@@ -13,15 +13,36 @@ namespace GitCredentialManager;
1313/// A wrapper for <see cref="ICommandContext"/> that overrides the namespace for credentials and also
1414/// allows git-less usage except for the git cache store.
1515/// </summary>
16- class CommandContextWrapper ( CommandContext context , string ? @namespace ) : ICommandContext
16+ class CommandContextAdapter : ICommandContext
1717{
18- readonly ISettings settings = new SettingsWrapper (
19- context . Settings is WindowsSettings ?
20- new NoGitWindowsSettings ( context . Environment , context . Git , context . Trace ) :
21- new NoGitSettings ( context . Environment , context . Git ) , @namespace ) ;
18+ readonly CommandContext context ;
19+ readonly ICredentialStore store ;
20+ readonly ISettings settings ;
21+ readonly IHttpClientFactory clientFactory ;
22+
23+ public CommandContextAdapter ( CommandContext context , string ? @namespace = default )
24+ {
25+ this . context = context ;
26+
27+ store = new CredentialStore ( this ) ;
28+
29+ settings = new SettingsAdapter (
30+ context . Settings is WindowsSettings ?
31+ new NoGitWindowsSettings ( context . Environment , context . Git , context . Trace ) :
32+ new NoGitSettings ( context . Environment , context . Git ) , @namespace ) ;
33+
34+ clientFactory = new HttpClientFactory (
35+ context . FileSystem , context . Trace , context . Trace2 , settings , context . Streams ) ;
36+ }
2237
2338 public ISettings Settings => settings ;
2439
40+ public ICredentialStore CredentialStore => store ;
41+
42+ public IHttpClientFactory HttpClientFactory => clientFactory ;
43+
44+ public IGit Git => new NoGit ( context . Git ) ;
45+
2546 #region pass-through impl.
2647
2748 public string ApplicationPath { get => ( ( ICommandContext ) context ) . ApplicationPath ; set => ( ( ICommandContext ) context ) . ApplicationPath = value ; }
@@ -40,12 +61,6 @@ context.Settings is WindowsSettings ?
4061
4162 public IFileSystem FileSystem => ( ( ICommandContext ) context ) . FileSystem ;
4263
43- public ICredentialStore CredentialStore => ( ( ICommandContext ) context ) . CredentialStore ;
44-
45- public IHttpClientFactory HttpClientFactory => ( ( ICommandContext ) context ) . HttpClientFactory ;
46-
47- public IGit Git => new NoGit ( context . Git ) ;
48-
4964 public IEnvironment Environment => ( ( ICommandContext ) context ) . Environment ;
5065
5166 public IProcessManager ProcessManager => ( ( ICommandContext ) context ) . ProcessManager ;
@@ -137,11 +152,14 @@ public bool TryGet(GitConfigurationLevel level, GitConfigurationType type, strin
137152 }
138153 }
139154
155+ /// <summary>Adapts <see cref="Settings"/> to use <see cref="NoGit"/>.</summary>
140156 class NoGitSettings ( IEnvironment environment , IGit git ) : Settings ( environment , new NoGit ( git ) ) { }
141157
158+ /// <summary>Adapts <see cref="WindowsSettings"/> to use <see cref="NoGit"/>.</summary>
142159 class NoGitWindowsSettings ( IEnvironment environment , IGit git , ITrace trace ) : WindowsSettings ( environment , new NoGit ( git ) , trace ) { }
143160
144- class SettingsWrapper ( ISettings settings , string ? @namespace ) : ISettings
161+ /// <summary>Allows overriding the credential namespace.</summary>
162+ class SettingsAdapter ( ISettings settings , string ? @namespace ) : ISettings
145163 {
146164 public string CredentialNamespace => @namespace ?? settings . CredentialNamespace ;
147165
0 commit comments