You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For an additional example that uses a <xref:Microsoft.Extensions.Configuration.Memory.MemoryConfigurationProvider>, see the [Bind an array](#bind-an-array) section.
In the preceding output, Index 3 has value `value40`, corresponding to `"4": "value40",` in `array.json`. The bound array indices are continuous and not bound to the configuration key index. The configuration binder isn't capable of binding `null` values or creating `null` entries in bound objects.
1271
1268
1272
-
:::moniker range="< aspnetcore-6.0"
1269
+
The missing configuration item for Index 3 can be supplied before binding to the `ArrayExample` instance by any configuration provider that reads the Index 3 key/value pair. In the following example, assume that the values provided by `array.json` in the preceding example are provided by an [in-memory collection](#memory-configuration-provider). The example shows how to load the Index 3 value from the [JSON Configuration Provider](#json-configuration-provider) before the collection is bound.
1273
1270
1274
-
The following code loads the `array:entries` configuration with the <xref:Microsoft.Extensions.Configuration.MemoryConfigurationBuilderExtensions.AddInMemoryCollection%2A> extension method:
Index #3 in the bound object holds the configuration data for the `array:4` configuration key and its value of `value4`. When configuration data containing an array is bound, the array indices in the configuration keys are used to iterate the configuration data when creating the object. A null value can't be retained in configuration data, and a null-valued entry isn't created in a bound object when an array in configuration keys skip one or more indices.
1348
-
1349
-
The missing configuration item for index #3 can be supplied before binding to the `ArrayExample` instance by any configuration provider that reads the index #3 key/value pair. Consider the following `Value3.json` file from the sample download:
1350
-
1351
-
```json
1352
-
{
1353
-
"array:entries:3": "value3"
1354
-
}
1355
-
```
1296
+
::: moniker-end
1356
1297
1357
-
The following code includes configuration for `Value3.json` and the `arrayDict``Dictionary`:
The preceding code results in the following bound array:
1423
1325
1424
-
```text
1425
-
Index: 0 Value: value0
1426
-
Index: 1 Value: value1
1427
-
Index: 2 Value: value2
1428
-
Index: 3 Value: value3
1429
-
Index: 4 Value: value4
1430
-
Index: 5 Value: value5
1326
+
```console
1327
+
Index: 0 Value: value00
1328
+
Index: 1 Value: value10
1329
+
Index: 2 Value: value20
1330
+
Index: 3 Value: value30
1331
+
Index: 4 Value: value40
1332
+
Index: 5 Value: value50
1431
1333
```
1432
1334
1433
-
Custom configuration providers aren't required to implement array binding.
1434
-
1435
-
:::moniker-end
1436
-
1437
1335
## Custom configuration provider
1438
1336
1439
1337
The sample app demonstrates how to create a basic configuration provider that reads configuration key-value pairs from a database using [Entity Framework (EF)](/ef/core/).
0 commit comments