Skip to content

Commit 3a46c4d

Browse files
authored
Merge pull request #101210 from mike-urnun-msft/patch-105
(Azure CXP) resolves #46138 #45869
2 parents 19e22d7 + d77f4ca commit 3a46c4d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

articles/azure-functions/functions-dotnet-dependency-injection.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ Values defined in [app settings](./functions-how-to-use-azure-function-app-setti
148148

149149
You can extract values from the `IConfiguration` instance into a custom type. Copying the app settings values to a custom type makes it easy test your services by making these values injectable. Settings read into the configuration instance must be simple key/value pairs.
150150

151-
Consider the following class that includes a property named consistent with an app setting.
151+
Consider the following class that includes a property named consistent with an app setting:
152152

153153
```csharp
154154
public class MyOptions
@@ -157,13 +157,23 @@ public class MyOptions
157157
}
158158
```
159159

160+
And a `local.settings.json` file that might structure the custom setting as follows:
161+
```json
162+
{
163+
"IsEncrypted": false,
164+
"Values": {
165+
"MyOptions:MyCustomSetting": "Foobar"
166+
}
167+
}
168+
```
169+
160170
From inside the `Startup.Configure` method, you can extract values from the `IConfiguration` instance into your custom type using the following code:
161171

162172
```csharp
163173
builder.Services.AddOptions<MyOptions>()
164174
.Configure<IConfiguration>((settings, configuration) =>
165175
{
166-
configuration.Bind(settings);
176+
configuration.GetSection("MyOptions").Bind(settings);
167177
});
168178
```
169179

0 commit comments

Comments
 (0)