@@ -6,11 +6,12 @@ footer: 'https://chris-ayers.com'
6
6
7
7
<!-- _footer: 'https://github.com/codebytes/dotnet-configuration-in-depth' -->
8
8
9
- ![ bg left] ( ./img/dotnet-logo.png )
10
-
11
9
# .NET Configuration in Depth
10
+
12
11
## Chris Ayers
13
12
13
+ ![ bg left] ( ./img/dotnet-logo.png )
14
+
14
15
---
15
16
16
17
![ bg left:40%] ( ./img/portrait.png )
@@ -23,14 +24,15 @@ footer: 'https://chris-ayers.com'
23
24
<i class =" fa-brands fa-linkedin " ></i > LinkedIn: - [ chris\- l\- ayers] ( https://linkedin.com/in/chris-l-ayers/ )
24
25
<i class =" fa fa-window-maximize " ></i > Blog: [ https://chris-ayers\.com/ ] ( https://chris-ayers.com/ )
25
26
<i class =" fa-brands fa-github " ></i > GitHub: [ Codebytes] ( https://github.com/codebytes )
26
- <i class =" fa-brands fa-mastodon " ></i > Mastodon: @Chrisayers @hachyderm.io
27
+ <i class =" fa-brands fa-mastodon " ></i > Mastodon: [ @Chrisayers @hachyderm.io] ( https://hachyderm.io/@Chrisayers )
27
28
~~ <i class =" fa-brands fa-twitter " ></i > Twitter: @Chris_L_Ayers~~
28
29
29
30
---
30
31
31
32
![ bg right:40% auto] ( ./img/dotnet-logo.png )
32
33
33
34
# Agenda
35
+
34
36
- What is configuration?
35
37
- How does .NET Framework handle configuration?
36
38
- How does .NET and ASP.NET handle configuration?
@@ -47,22 +49,25 @@ footer: 'https://chris-ayers.com'
47
49
<div >
48
50
49
51
## <i class =" fa fa-sliders " ></i > Settings
50
- * Retry Times
51
- * Queue Length
52
+
53
+ - Retry Times
54
+ - Queue Length
52
55
53
56
</div >
54
57
<div >
55
58
56
59
## <i class =" fa-sharp fa-solid fa-flag " ></i > Feature Flags
57
- * Per User
58
- * Percentage
60
+
61
+ - Per User
62
+ - Percentage
59
63
60
64
</div >
61
65
<div >
62
66
63
67
## <i class =" fa fa-key " ></i > Secrets
64
- * Connection Strings
65
- * App Registration
68
+
69
+ - Connection Strings
70
+ - App Registration
66
71
67
72
</div >
68
73
</div >
@@ -98,13 +103,13 @@ footer: 'https://chris-ayers.com'
98
103
99
104
# Web.Config
100
105
101
- * Limited to Key\- Value string pairs
102
- * Accessed through a static ConfigurationManager Class
103
- * Dependency Injection was not provided out of the box
104
- * Transformation through difficult syntax
105
- * Slow Cheetah
106
- * Hard to unit test
107
- * Easy to leak secrets
106
+ - Limited to Key\- Value string pairs
107
+ - Accessed through a static ConfigurationManager Class
108
+ - Dependency Injection was not provided out of the box
109
+ - Transformation through difficult syntax
110
+ - Slow Cheetah
111
+ - Hard to unit test
112
+ - Easy to leak secrets
108
113
109
114
---
110
115
@@ -141,7 +146,6 @@ footer: 'https://chris-ayers.com'
141
146
142
147
```
143
148
144
-
145
149
``` csharp
146
150
private string greeting = " " ;
147
151
private int majorDotNetVersion = 0 ;
@@ -160,7 +164,6 @@ footer: 'https://chris-ayers.com'
160
164
161
165
# .NET Core/5/6/7/8 <br /> ASP.NET Configuration
162
166
163
-
164
167
![ bg left fit 90%] ( ./img/gears.png )
165
168
166
169
---
@@ -173,7 +176,6 @@ footer: 'https://chris-ayers.com'
173
176
174
177
# Order Matters
175
178
176
-
177
179
![ center width:980] ( ./img/configuration-source.png )
178
180
179
181
---
@@ -230,6 +232,7 @@ Settings? settings =
230
232
---
231
233
232
234
# Hierarchical Configuration Data
235
+
233
236
## Keys are Flattened
234
237
235
238
<div class =" columns " >
@@ -252,14 +255,14 @@ Settings? settings =
252
255
</div >
253
256
<div >
254
257
255
-
256
258
``` json
257
259
{
258
260
"Parent:FavoriteNumber" : 7 ,
259
261
"Parent:Child:Name" : " Example" ,
260
262
"Parent:Child:GrandChild:Age" : 3
261
263
}
262
264
```
265
+
263
266
</div >
264
267
</div >
265
268
@@ -271,12 +274,14 @@ Settings? settings =
271
274
<div >
272
275
273
276
## <i class =" fa fa-terminal " ></i > Console
274
- - No Configuration
277
+
278
+ - No Configuration
275
279
276
280
</div >
277
281
<div >
278
282
279
283
## .NET Generic Host
284
+
280
285
- JSON
281
286
- appsettings.json
282
287
- appsettings.{Environment}.json
@@ -288,6 +293,7 @@ Settings? settings =
288
293
<div >
289
294
290
295
## <i class =" fa-regular fa-window-maximize " ></i > ASP.NET
296
+
291
297
- JSON
292
298
- appsettings.json
293
299
- appsettings.{Environment}.json
@@ -302,27 +308,27 @@ Settings? settings =
302
308
303
309
# Configuration Providers
304
310
305
-
306
311
<div class =" columns " >
307
312
<div >
308
313
309
314
## File-based
310
- * JSON
311
- * XML
312
- * INI
313
- * Key-per-file
315
+
316
+ - JSON
317
+ - XML
318
+ - INI
319
+ - Key-per-file
314
320
315
321
</div >
316
322
<div >
317
323
318
324
## Others
319
325
320
- * Environment variables
321
- * Command-line
322
- * In-Memory
323
- * User Secrets
324
- * Azure Key Vault
325
- * Azure App Configuration
326
+ - Environment variables
327
+ - Command-line
328
+ - In-Memory
329
+ - User Secrets
330
+ - Azure Key Vault
331
+ - Azure App Configuration
326
332
327
333
</div >
328
334
</div >
@@ -337,6 +343,7 @@ Settings? settings =
337
343
``` xml
338
344
<PackageReference Include =" Microsoft.Extensions.Configuration.Json" Version =" 8.0.0" />
339
345
```
346
+
340
347
``` csharp
341
348
IHostEnvironment env = builder .Environment ;
342
349
@@ -378,6 +385,7 @@ builder.Configuration
378
385
``` xml
379
386
<PackageReference Include =" Microsoft.Extensions.Configuration.Xml" Version =" 8.0.0" />
380
387
```
388
+
381
389
``` csharp
382
390
IHostEnvironment env = builder .Environment ;
383
391
@@ -419,6 +427,7 @@ builder.Configuration
419
427
``` xml
420
428
<PackageReference Include =" Microsoft.Extensions.Configuration.Ini" Version =" 8.0.0" />
421
429
```
430
+
422
431
``` csharp
423
432
IHostEnvironment env = builder .Environment ;
424
433
@@ -483,7 +492,7 @@ set TransientFaultHandlingOptions__AutoRetryDelay="00:00:13"
483
492
<div class =" columns " >
484
493
<div >
485
494
486
- - There are built-in prefixes, like
495
+ - There are built-in prefixes, like
487
496
- ASPNETCORE_ for ASP.NET Core
488
497
- DOTNET_ for .NET Core
489
498
- You can provide your own prefix
@@ -495,12 +504,14 @@ set TransientFaultHandlingOptions__AutoRetryDelay="00:00:13"
495
504
builder .Configuration .AddEnvironmentVariables (
496
505
prefix : " MyCustomPrefix_" );
497
506
```
507
+
498
508
``` bash
499
509
set MyCustomPrefix_MyKey=" My key with MyCustomPrefix_"
500
510
set MyCustomPrefix_Position__Title=Editor_with_custom
501
511
set MyCustomPrefix_Position__Name=Environment
502
512
dotnet run
503
513
```
514
+
504
515
</div >
505
516
</div >
506
517
@@ -535,7 +546,6 @@ dotnet run
535
546
- Must be non-abstract with a public parameterless constructor
536
547
- Contain public read-write properties to bind (fields are not bound)
537
548
538
-
539
549
</div >
540
550
<div >
541
551
@@ -576,11 +586,13 @@ public class FileOptions
576
586
577
587
## Resources
578
588
579
- #### GitHub Repo
580
- #### https://github.com/codebytes/dotnet-configuration-in-depth
589
+ ### GitHub Repo
581
590
582
- #### Blog
583
- #### https://chris-ayers.com
591
+ - [ https://github.com/codebytes/dotnet-configuration-in-depth ] ( https://github.com/codebytes/dotnet-configuration-in-depth )
592
+
593
+ ### Docs
594
+
595
+ - [ .NET Configuration Docs] ( https://learn.microsoft.com/en-us/dotnet/core/extensions/configuration )
584
596
585
597
</div >
586
598
@@ -594,8 +606,8 @@ public class FileOptions
594
606
<i class =" fa-brands fa-linkedin " ></i > LinkedIn: - [ chris\- l\- ayers] ( https://linkedin.com/in/chris-l-ayers/ )
595
607
<i class =" fa fa-window-maximize " ></i > Blog: [ https://chris-ayers\.com/ ] ( https://chris-ayers.com/ )
596
608
<i class =" fa-brands fa-github " ></i > GitHub: [ Codebytes] ( https://github.com/codebytes )
597
- <i class =" fa-brands fa-mastodon " ></i > Mastodon: @Chrisayers @hachyderm.io
609
+ <i class =" fa-brands fa-mastodon " ></i > Mastodon: [ @Chrisayers @hachyderm.io] ( https://hachyderm.io/@Chrisayers )
598
610
~~ <i class =" fa-brands fa-twitter " ></i > Twitter: @Chris_L_Ayers~~
599
611
600
612
</div >
601
- </div >
613
+ </div >
0 commit comments