@@ -13,15 +13,36 @@ namespace GitCredentialManager;
13
13
/// A wrapper for <see cref="ICommandContext"/> that overrides the namespace for credentials and also
14
14
/// allows git-less usage except for the git cache store.
15
15
/// </summary>
16
- class CommandContextWrapper ( CommandContext context , string ? @namespace ) : ICommandContext
16
+ class CommandContextAdapter : ICommandContext
17
17
{
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
+ }
22
37
23
38
public ISettings Settings => settings ;
24
39
40
+ public ICredentialStore CredentialStore => store ;
41
+
42
+ public IHttpClientFactory HttpClientFactory => clientFactory ;
43
+
44
+ public IGit Git => new NoGit ( context . Git ) ;
45
+
25
46
#region pass-through impl.
26
47
27
48
public string ApplicationPath { get => ( ( ICommandContext ) context ) . ApplicationPath ; set => ( ( ICommandContext ) context ) . ApplicationPath = value ; }
@@ -40,12 +61,6 @@ context.Settings is WindowsSettings ?
40
61
41
62
public IFileSystem FileSystem => ( ( ICommandContext ) context ) . FileSystem ;
42
63
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
-
49
64
public IEnvironment Environment => ( ( ICommandContext ) context ) . Environment ;
50
65
51
66
public IProcessManager ProcessManager => ( ( ICommandContext ) context ) . ProcessManager ;
@@ -137,11 +152,14 @@ public bool TryGet(GitConfigurationLevel level, GitConfigurationType type, strin
137
152
}
138
153
}
139
154
155
+ /// <summary>Adapts <see cref="Settings"/> to use <see cref="NoGit"/>.</summary>
140
156
class NoGitSettings ( IEnvironment environment , IGit git ) : Settings ( environment , new NoGit ( git ) ) { }
141
157
158
+ /// <summary>Adapts <see cref="WindowsSettings"/> to use <see cref="NoGit"/>.</summary>
142
159
class NoGitWindowsSettings ( IEnvironment environment , IGit git , ITrace trace ) : WindowsSettings ( environment , new NoGit ( git ) , trace ) { }
143
160
144
- class SettingsWrapper ( ISettings settings , string ? @namespace ) : ISettings
161
+ /// <summary>Allows overriding the credential namespace.</summary>
162
+ class SettingsAdapter ( ISettings settings , string ? @namespace ) : ISettings
145
163
{
146
164
public string CredentialNamespace => @namespace ?? settings . CredentialNamespace ;
147
165
0 commit comments