@@ -76,15 +76,12 @@ It is possible to distinguish between error happening during _load_ and _reload_
7676by using ` OnLoadException ` and ` OnReloadException ` respectively.
7777
7878``` csharp
79+ // ignore exception (do not throw)
7980builder .Configuration .AddSecretsManager (
80- source =>
81- {
82- source .SecretName = " my-secret-secrets" ;
83-
84- // ignore exception (do not throw)
85- source .OnLoadException = ctx => { ctx .Ignore = true ; };
86- source .OnReloadException = ctx => { ctx .Ignore = true ; };
87- });
81+ " my-secret-secrets" ,
82+ source => source
83+ .OnLoadException (ctx => { ctx .Ignore = true ; })
84+ .OnReloadException (ctx => { ctx .Ignore = true ; }));
8885```
8986
9087Callbacks receive ` SecretsManagerExceptionContext ` which can be examined to decide whether to ignore the exception or not by flagging its ` Ignore ` property.
@@ -95,11 +92,8 @@ If omitted, the latest version of the secret will be used, however it is possibl
9592
9693``` csharp
9794builder .Configuration .AddSecretsManager (
98- source =>
99- {
100- source .SecretName = " my-secret-secrets" ;
101- source .Version = new SecretVersion { VersionId = " d6d1b757d46d449d1835a10869dfb9d1" };
102- });
95+ " my-secret-secrets" ,
96+ source => source .WithVersion (versionId : " d6d1b757d46d449d1835a10869dfb9d1" ));
10397```
10498
10599### Configuration key prefix
@@ -124,14 +118,10 @@ In some cases, custom format may be used - either a complex JSON object or even
124118In order to support such scenarios, it is possible to specify custom secret processor:
125119
126120``` csharp
121+ // implements `ISecretsProcessor`
127122builder .Configuration .AddSecretsManager (
128- source =>
129- {
130- source .SecretName = " my-secret-secrets" ;
131-
132- // implements `ISecretsProcessor`
133- source .Processor = new MyCustomSecretProcessor ();
134- });
123+ " my-secret-secrets" ,
124+ source => source .WithProcessor (new MyCustomSecretProcessor ()));
135125```
136126
137127There's helper class [ ` SecretProcessor<T> ` ] ( src/W4k.Extensions.Configuration.Aws.SecretsManager/SecretProcessor.cs ) which
@@ -147,35 +137,38 @@ By default, only [`KeyDelimiterTransformer`](src/W4k.Extensions.Configuration.Aw
147137To add custom transformation, use property ` KeyTransformers ` :
148138
149139``` csharp
140+ // implements `IConfigurationKeyTransformer`
150141builder .Configuration .AddSecretsManager (
151- source =>
152- {
153- source .SecretName = " my-secret-secrets" ;
154-
155- // implements `IConfigurationKeyTransformer`
156- source .KeyTransformers .Add (new MyCustomKeyTransformer ());
157- });
142+ " my-secret-secrets" ,
143+ source => source .AddKeyTransformer (new MyCustomKeyTransformer ()));
158144```
159145
160- It is also possible to clear transformers by simply calling ` Clear() ` method.
146+ It is also possible to clear transformers by simply calling ` Clear() ` , respectively ` ClearKeyTransformers() ` , method.
161147
162148``` csharp
149+ // assigning values directly to `SecretsManagerConfigurationSource`
163150source .KeyTransformers .Clear ();
151+
152+ // using `SecretsManagerConfigurationBuilder`
153+ source .ClearKeyTransformers ();
164154```
165155
166156### Refreshing secrets
167157
168158By default, secrets are not refreshed. In order to enable refreshing, you can configure ` ConfigurationWatcher ` property:
169159
170160``` csharp
161+ // implements `IConfigurationWatcher`
162+ builder .Configuration .AddSecretsManager (
163+ " my-secret-secrets" ,
164+ source => source .WithConfigurationWatcher (new SecretsManagerPollingWatcher (TimeSpan .FromMinutes (5 )));
165+ ```
166+
167+ ```csharp
168+ // uses `SecretsManagerPollingWatcher`
171169builder .Configuration .AddSecretsManager (
172- source =>
173- {
174- source .SecretName = " my-secret-secrets" ;
175-
176- // implements `IConfigurationWatcher`
177- source .ConfigurationWatcher = new SecretsManagerPollingWatcher (TimeSpan .FromMinutes (5 ));
178- });
170+ " my-secret-secrets" ,
171+ source => source .WithPollingWatcher (TimeSpan .FromMinutes (5 ));
179172```
180173
181174When refreshing secrets , use `IOptionsSnapshot < T > ` or `IOptionsMonitor < T > ` instead of just `IOptions < T > `.
@@ -193,11 +186,8 @@ it is possible to configure timeout:
193186
194187```csharp
195188builder .Configuration .AddSecretsManager (
196- source =>
197- {
198- source .SecretName = " my-secret-secrets" ;
199- source .Timeout = TimeSpan .FromSeconds (42 );
200- });
189+ " my-secret-secrets" ,
190+ source => source .WithTimeout (TimeSpan .FromSeconds (42 )));
201191```
202192
203193Default timeout value can be found at [`SecretsManagerConfigurationSource `](src / W4k .Extensions .Configuration .Aws .SecretsManager / SecretsManagerConfigurationSource .cs ).
@@ -240,14 +230,10 @@ When listener is registered this way in very early stage of the application, it
240230It is possible to configure logging for the provider :
241231
242232```csharp
233+ // using Microsoft.Extensions.Logging
243234builder .Configuration .AddSecretsManager (
244- source =>
245- {
246- source .SecretName = " my-secret-secrets" ;
247-
248- // using Microsoft.Extensions.Logging
249- source .LoggerFactory = LoggerFactory .Create (logging => logging .AddConsole ());
250- });
235+ " my-secret-secrets" ,
236+ source => source .WithLoggerFactory (LoggerFactory .Create (logging => logging .AddConsole ())));
251237```
252238
253239By default , logging is disabled (by using `NullLoggerFactory `).
0 commit comments