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
@@ -37,70 +37,17 @@ Complete the following steps to register the services you need:
37
37
38
38
3. In the `Program.cs` file, invoke the `AddAzureClients` extension method from the `Microsoft.Extensions.Azure` library to register a client for each service. Some services use additional subclients, which you can also register for dependency injection.
In the preceding code, the `clientBuilder.UseCredential()` method accepts an instance of `DefaultAzureCredential` that will be reused across your registered services. `DefaultAzureCredential` discovers available credentials in the current environment and use them to connect to Azure services. The full order and locations in which `DefaultAzureCredential` looks for credentials can be found in the [`Azure Identity library overview`](/dotnet/api/overview/azure/Identity-readme#defaultazurecredential).
138
65
@@ -150,102 +77,41 @@ For example, when you run the app locally, `DefaultAzureCredential` discovers an
150
77
- Workload identity
151
78
- Managed identity
152
79
153
-
## Set up service configurations
80
+
## Set up configurations
154
81
155
82
Azure service clients support configurations to change their default behaviors. There are two ways to configure service clients:
156
83
157
84
- You can [store configurations in environment-dependent JSON files](/dotnet/core/extensions/configuration-providers#json-configuration-provider). Configuration files are generally the recommended approach because they simplify app deployments between environments and help eliminate hard coded values.
158
85
- You can also configurations directly in your code when you register the service client. For example, in the [Register clients and subclients](#register-service-clients-and-subclients) section, you explicitly passed the Uri-typed variables to the client constructors.
159
86
160
-
The following example uses an `appsettings.Development.json` file to store development environment settings and an `appsettings.Production.json` file to contain production environment settings. You can add any properties from the [`ClientOptions`](/dotnet/api/azure.core.clientoptions) class into the JSON file.
161
-
162
-
1. Update the `appsettings.<environment>.json` file in your app to match the following structure:
The following steps use an `appsettings.Development.json` file to store development environment settings and an `appsettings.Production.json` file to contain production environment settings. You can add any properties from the [`ClientOptions`](/dotnet/api/azure.core.clientoptions) class into the JSON file.
88
+
89
+
### Configure registered services
90
+
91
+
1. Update the `appsettings.<environment>.json` file in your app with the highlighted service configurations:
- The top-level key names, `KeyVault`, `ServiceBus`, and `Storage`, are arbitrary names used to reference the config sections from your code. All other key names hold significance, and JSON serialization is performed in a case-insensitive manner.
181
98
- The `KeyVault:VaultUri`, `ServiceBus:Namespace`, and `Storage:ServiceUri` key values map to the `Uri`- and `string`-typed arguments of the <xref:Azure.Security.KeyVault.Secrets.SecretClient.%23ctor(System.Uri,Azure.Core.TokenCredential,Azure.Security.KeyVault.Secrets.SecretClientOptions)?displayProperty=fullName>, <xref:Azure.Messaging.ServiceBus.ServiceBusClient.%23ctor(System.String)?displayProperty=fullName>, and <xref:Azure.Storage.Blobs.BlobServiceClient.%23ctor(System.Uri,Azure.Core.TokenCredential,Azure.Storage.Blobs.BlobClientOptions)?displayProperty=fullName> constructor overloads, respectively. The `TokenCredential` variants of the constructors are used because a default `TokenCredential` is set via the <xref:Microsoft.Extensions.Azure.AzureClientFactoryBuilder.UseCredential(Azure.Core.TokenCredential)?displayProperty=fullName> method call.
182
99
183
-
1. Retrieve the settings in the JSON configuration file using `IConfiguration` and pass them into your service registrations:
At some point, you may want to change default Azure client configurations globally or for a specific service client. For example, you may want different retry settings or to use a different service API version. You can set the retry settings globally or on a per-service basis.
204
107
205
108
1. Update your configuration file to set default Azure settings, such as a new default retry policy and a specific retry policy for Azure Key Vault:
206
109
207
-
```json
208
-
{
209
-
"AzureDefaults": {
210
-
"Diagnostics": {
211
-
"IsTelemetryDisabled": false,
212
-
"IsLoggingContentEnabled": true
213
-
},
214
-
"Retry": {
215
-
"MaxRetries": 3,
216
-
"Mode": "Exponential"
217
-
}
218
-
},
219
-
"KeyVault": {
220
-
"VaultUri": "https://mykeyvault.vault.azure.net",
221
-
"Retry": {
222
-
"maxRetries": 10
223
-
}
224
-
}
225
-
}
226
-
```
227
-
228
-
2. Add a call to the `ConfigureDefaults` extension method in your `AddAzureClients` setup:
2. In the `Program.cs` file, the `ConfigureDefaults` extension method `AddAzureClients` retrieves the default settings and applies them to your services:
@@ -264,14 +130,4 @@ The following table depicts how the Azure SDK for .NET `EventLevel` maps to the
264
130
265
131
You can change default log levels and other settings using the same JSON configurations outlined in the [configure authentication](#configure-authentication) section. For example, toggle a the `ServiceBusClient` log level to `Debug` by setting the `Logging:LogLevel:Azure.Messaging.ServiceBus` key as follows:
0 commit comments