diff --git a/docs/azure/sdk/dependency-injection.md b/docs/azure/sdk/dependency-injection.md index 824654783f63d..70b51a0ada23d 100644 --- a/docs/azure/sdk/dependency-injection.md +++ b/docs/azure/sdk/dependency-injection.md @@ -3,56 +3,62 @@ title: Dependency injection with the Azure SDK for .NET description: Learn how to use dependency injection with the Azure SDK for .NET client libraries. ms.topic: how-to ms.custom: devx-track-dotnet, engagement-fy23 -ms.date: 2/28/2023 +ms.date: 07/21/2023 --- # Dependency injection with the Azure SDK for .NET -This article demonstrates how to register Azure service clients from the [latest Azure SDKs for .NET](https://azure.github.io/azure-sdk/releases/latest/index.html#net) for [dependency injection in an ASP.NET Core app](/aspnet/core/fundamentals/dependency-injection). Every ASP.NET Core app starts up by using the instructions provided in the _Program.cs_ file. +This article demonstrates how to register Azure service clients from the [latest Azure client libraries for .NET](https://azure.github.io/azure-sdk/releases/latest/index.html#net) for [dependency injection in a .NET app](/dotnet/core/extensions/dependency-injection). Every modern .NET app starts up by using the instructions provided in a *Program.cs* file. -To configure the service clients, first add the following NuGet packages to your project: +## Install packages -- [Microsoft.Extensions.Azure](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/extensions/Microsoft.Extensions.Azure/README.md) -- [Azure.Identity](https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/identity/Azure.Identity/README.md) -- The `Azure.*` package you'd like to use. +To register and configure service clients from an [`Azure.`-prefixed package](/dotnet/azure/sdk/packages#libraries-using-azurecore): -The sample code in this article uses Key Vault secrets and Blob Storage for demonstration purposes. +1. Install the [Microsoft.Extensions.Azure](https://www.nuget.org/packages/Microsoft.Extensions.Azure) package in your project: + + ```dotnetcli + dotnet add package Microsoft.Extensions.Azure + ``` + +1. Install the [Azure.Identity](https://www.nuget.org/packages/Azure.Identity) package to configure a `TokenCredential` type to use for authenticating all registered clients that accept such a type: + + ```dotnetcli + dotnet add package Azure.Identity + ``` + +For demonstration purposes, the sample code in this article uses the Key Vault Secrets and Blob Storage libraries. Install the following packages to follow along: ```dotnetcli -dotnet add package Microsoft.Extensions.Azure -dotnet add package Azure.Identity dotnet add package Azure.Security.KeyVault.Secrets dotnet add package Azure.Storage.Blobs ``` -## Register client +## Register clients -In the _Program.cs_ file, register a client for each service: +In the *Program.cs* file, invoke the extension method to register a client for each service. The following code samples provide guidance on application builders from the `Microsoft.AspNetCore.Builder` and `Microsoft.Extensions.Hosting` namespaces. -```csharp -builder.Services.AddAzureClients(clientBuilder => -{ - // Add a KeyVault client - clientBuilder.AddSecretClient(keyVaultUrl); +### [WebApplicationBuilder](#tab/web-app-builder) - // Add a Storage account client - clientBuilder.AddBlobServiceClient(storageUrl); +:::code language="csharp" source="snippets/dependency-injection/WebApplicationBuilder/Program.cs" id="snippet_WebApplicationBuilder" highlight="6-11"::: - // Use DefaultAzureCredential by default - clientBuilder.UseCredential(new DefaultAzureCredential()); -}); +### [HostApplicationBuilder](#tab/host-app-builder) -builder.Services.AddControllers(); -``` +:::code language="csharp" source="snippets/dependency-injection/HostApplicationBuilder/Program.cs" highlight="7-12"::: + +### [HostBuilder](#tab/host-builder) + +:::code language="csharp" source="snippets/dependency-injection/HostBuilder/Program.cs" id="snippet_HostBuilder" highlight="8-13"::: + +--- In the preceding code: -* You specify the `Uri`-typed `keyVaultUrl` and `storageUrl` variables. The [Store configuration separately from code](#store-configuration-separately-from-code) section shows how you can avoid specifying the URLs explicitly. -* is used for authentication. `DefaultAzureCredential` chooses the best authentication mechanism based on your environment, allowing you to move your app seamlessly from development to production with no code changes. +* Key Vault Secrets and Blob Storage clients are registered using and , respectively. The `Uri`-typed arguments are passed. To avoid specifying these URLs explicitly, see the [Store configuration separately from code](#store-configuration-separately-from-code) section. +* is used to satisfy the `TokenCredential` argument requirement for each registered client. When one of the clients is created, `DefaultAzureCredential` is used to authenticate. ## Use the registered clients -With the clients registered in the `AddAzureClients`, you can now use them: +With the clients registered, as described in the [Register clients](#register-clients) section, you can now use them. In the following example, [constructor injection](/dotnet/core/extensions/dependency-injection#constructor-injection-behavior) is used to obtain the Blob Storage client in an ASP.NET Core API controller: ```csharp [ApiController] @@ -66,16 +72,18 @@ public class MyApiController : ControllerBase _blobServiceClient = blobServiceClient; } - // Get a list of all the blobs in the demo container [HttpGet] public async Task> Get() { - var containerClient = _blobServiceClient.GetBlobContainerClient("demo"); + BlobContainerClient containerClient = + _blobServiceClient.GetBlobContainerClient("demo"); var results = new List(); + await foreach (BlobItem blob in containerClient.GetBlobsAsync()) { results.Add(blob.Name); } + return results.ToArray(); } } @@ -83,7 +91,7 @@ public class MyApiController : ControllerBase ## Store configuration separately from code -In the [Register client](#register-client) section, you explicitly specify the `keyVaultUrl` and `storageUrl` variables. This approach could cause problems when you run code against different environments during development and production. The .NET team suggests [storing such configurations in environment-dependent JSON files](../../core/extensions/configuration-providers.md#json-configuration-provider). For example, you can have an _appsettings.Development.json_ file containing development environment settings. Another _appsettings.Production.json_ file would contain production environment settings, and so on. The file format is: +In the [Register clients](#register-clients) section, you explicitly passed the `Uri`-typed variables to the client constructors. This approach could cause problems when you run code against different environments during development and production. The .NET team suggests [storing such configurations in environment-dependent JSON files](../../core/extensions/configuration-providers.md#json-configuration-provider). For example, you can have an *appsettings.Development.json* file containing development environment settings. Another *appsettings.Production.json* file would contain production environment settings, and so on. The file format is: ```json { @@ -106,43 +114,98 @@ In the [Register client](#register-client) section, you explicitly specify the ` } ``` -You can add any options from into the JSON file's `AzureDefaults` section. One of the options is the retry policy. For more information, see [Configure a new retry policy](#configure-a-new-retry-policy). +You can add any properties from the class into the JSON file. The settings in the JSON configuration file can be retrieved using . + +### [WebApplicationBuilder](#tab/web-app-builder) + +```csharp +builder.Services.AddAzureClients(clientBuilder => +{ + clientBuilder.AddSecretClient( + builder.Configuration.GetSection("KeyVault")); + + clientBuilder.AddBlobServiceClient( + builder.Configuration.GetSection("Storage")); + + clientBuilder.UseCredential(new DefaultAzureCredential()); -Since the `Configuration` object is a member of the `builder` instance, you can configure secrets: + // Set up any default settings + clientBuilder.ConfigureDefaults( + builder.Configuration.GetSection("AzureDefaults")); +}); +``` + +### [HostApplicationBuilder](#tab/host-app-builder) ```csharp builder.Services.AddAzureClients(clientBuilder => { - // Add a KeyVault client - clientBuilder.AddSecretClient(builder.Configuration.GetSection("KeyVault")); + clientBuilder.AddSecretClient( + builder.Configuration.GetSection("KeyVault")); - // Add a storage account client - clientBuilder.AddBlobServiceClient(builder.Configuration.GetSection("Storage")); + clientBuilder.AddBlobServiceClient( + builder.Configuration.GetSection("Storage")); - // Use DefaultAzureCredential by default clientBuilder.UseCredential(new DefaultAzureCredential()); // Set up any default settings - clientBuilder.ConfigureDefaults(builder.Configuration.GetSection("AzureDefaults")); + clientBuilder.ConfigureDefaults( + builder.Configuration.GetSection("AzureDefaults")); }); +``` + +### [HostBuilder](#tab/host-builder) -builder.Services.AddControllers(); +```csharp +IHost host = Host.CreateDefaultBuilder(args) + .ConfigureServices((hostContext, services) => + { + services.AddHostedService(); + services.AddAzureClients(clientBuilder => + { + clientBuilder.AddSecretClient( + hostContext.Configuration.GetSection("KeyVault")); + + clientBuilder.AddBlobServiceClient( + hostContext.Configuration.GetSection("Storage")); + + clientBuilder.UseCredential(new DefaultAzureCredential()); + + // Set up any default settings + clientBuilder.ConfigureDefaults( + hostContext.Configuration.GetSection("AzureDefaults")); + }); + }) + .Build(); ``` +--- + +In the preceding JSON sample: + +* The top-level key names, `AzureDefaults`, `KeyVault`, and `Storage`, are arbitrary. All other key names hold significance, and JSON serialization is performed in a case-insensitive manner. +* The `AzureDefaults.Retry` object literal: + * Represents the [retry policy configuration settings](#configure-a-new-retry-policy). + * Corresponds to the property. Within that object literal, you find the `MaxRetries` key, which corresponds to the property. +* The `KeyVault:VaultUri` and `Storage:ServiceUri` key values map to the `Uri`-typed arguments of the and constructor overloads, respectively. The `TokenCredential` variants of the constructors are used because a default `TokenCredential` is set via the method call. + ## Configure multiple service clients with different names -Assume you have two storage accounts: one for private information and one for public information. Your app transfers data from the public to private storage account after some operation. You need to have two storage service clients. To set up these clients in the _Program.cs_ file: +Imagine you have two storage accounts: one for private information and another for public information. Your app transfers data from the public to the private storage account after some operation. You need to have two storage service clients. To differentiate those two clients, use the extension method: ```csharp builder.Services.AddAzureClients(clientBuilder => { - clientBuilder.AddBlobServiceClient(builder.Configuration.GetSection("PublicStorage")); - clientBuilder.AddBlobServiceClient(builder.Configuration.GetSection("PrivateStorage")) + clientBuilder.AddBlobServiceClient( + builder.Configuration.GetSection("PublicStorage")); + + clientBuilder.AddBlobServiceClient( + builder.Configuration.GetSection("PrivateStorage")) .WithName("PrivateStorage"); }); ``` -In your controller, you can access the named service clients using : +Using an ASP.NET Core controller as an example, access the named service client using the interface: ```csharp public class HomeController : Controller @@ -164,7 +227,7 @@ The unnamed service client is still available in the same way as before. Named c ## Configure a new retry policy -At some point, you might want to change the default settings for a service client. You may want different retry settings or to use a different service API version, for example. You can set the retry settings globally or on a per-service basis. Assume you have the following _appsettings.json_ file: +At some point, you may want to change the default settings for a 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. Assume you have the following *appsettings.json* file in your ASP.NET Core project: ```json { @@ -185,24 +248,28 @@ At some point, you might want to change the default settings for a service clien } ``` -You could change the retry policy depending on your needs like so: +You can change the retry policy to suit your needs like so: ```csharp builder.Services.AddAzureClients(clientBuilder => { // Establish the global defaults - clientBuilder.ConfigureDefaults(builder.Configuration.GetSection("AzureDefaults")); + clientBuilder.ConfigureDefaults( + builder.Configuration.GetSection("AzureDefaults")); clientBuilder.UseCredential(new DefaultAzureCredential()); // A Key Vault Secrets client using the global defaults - clientBuilder.AddSecretClient(builder.Configuration.GetSection("KeyVault")); + clientBuilder.AddSecretClient( + builder.Configuration.GetSection("KeyVault")); - // A Storage client with a custom retry policy - clientBuilder.AddBlobServiceClient(builder.Configuration.GetSection("Storage")) + // A Blob Storage client with a custom retry policy + clientBuilder.AddBlobServiceClient( + builder.Configuration.GetSection("Storage")) .ConfigureOptions(options => options.Retry.MaxRetries = 10); // A named storage client with a different custom retry policy - clientBuilder.AddBlobServiceClient(builder.Configuration.GetSection("CustomStorage")) + clientBuilder.AddBlobServiceClient( + builder.Configuration.GetSection("CustomStorage")) .WithName("CustomStorage") .ConfigureOptions(options => { @@ -213,7 +280,7 @@ builder.Services.AddAzureClients(clientBuilder => }); ``` -You can also place policy overrides in the _appsettings.json_ file: +You can also place retry policy overrides in the *appsettings.json* file: ```json { @@ -228,6 +295,6 @@ You can also place policy overrides in the _appsettings.json_ file: ## See also -- [Dependency injection in .NET](../../core/extensions/dependency-injection.md) -- [Configuration in .NET](../../core/extensions/configuration.md) -- [Configuration in ASP.NET Core](/aspnet/core/fundamentals/configuration) +* [Dependency injection in ASP.NET Core](/aspnet/core/fundamentals/dependency-injection) +* [Configuration in .NET](/dotnet/core/extensions/configuration) +* [Configuration in ASP.NET Core](/aspnet/core/fundamentals/configuration) diff --git a/docs/azure/sdk/logging.md b/docs/azure/sdk/logging.md index d911342905a26..839863a5f3e25 100644 --- a/docs/azure/sdk/logging.md +++ b/docs/azure/sdk/logging.md @@ -154,7 +154,7 @@ Using the Azure Service Bus library as an example, complete the following steps: ### Logging without client registration -There are scenarios in which [registering an Azure SDK library's client with the DI container](dependency-injection.md#register-client) is either impossible or unnecessary: +There are scenarios in which [registering an Azure SDK library's client with the DI container](dependency-injection.md#register-clients) is either impossible or unnecessary: - The Azure SDK library doesn't include an `IServiceCollection` extension method to register a client in the DI container. - Your app uses Azure extension libraries that depend on other Azure SDK libraries. Examples of such Azure extension libraries include: diff --git a/docs/azure/sdk/snippets/dependency-injection/Directory.Packages.props b/docs/azure/sdk/snippets/dependency-injection/Directory.Packages.props new file mode 100644 index 0000000000000..e0495eadc37f5 --- /dev/null +++ b/docs/azure/sdk/snippets/dependency-injection/Directory.Packages.props @@ -0,0 +1,14 @@ + + + true + + + + + + + + + + + \ No newline at end of file diff --git a/docs/azure/sdk/snippets/dependency-injection/HostApplicationBuilder/HostApplicationBuilder.csproj b/docs/azure/sdk/snippets/dependency-injection/HostApplicationBuilder/HostApplicationBuilder.csproj new file mode 100644 index 0000000000000..219deff185e56 --- /dev/null +++ b/docs/azure/sdk/snippets/dependency-injection/HostApplicationBuilder/HostApplicationBuilder.csproj @@ -0,0 +1,17 @@ + + + + Exe + net7.0 + enable + enable + + + + + + + + + + diff --git a/docs/azure/sdk/snippets/dependency-injection/HostApplicationBuilder/Program.cs b/docs/azure/sdk/snippets/dependency-injection/HostApplicationBuilder/Program.cs new file mode 100644 index 0000000000000..f5c8976d41b16 --- /dev/null +++ b/docs/azure/sdk/snippets/dependency-injection/HostApplicationBuilder/Program.cs @@ -0,0 +1,15 @@ +using Azure.Identity; +using Microsoft.Extensions.Azure; +using Microsoft.Extensions.Hosting; + +HostApplicationBuilder builder = Host.CreateApplicationBuilder(args); + +builder.Services.AddAzureClients(clientBuilder => +{ + clientBuilder.AddSecretClient(new Uri("")); + clientBuilder.AddBlobServiceClient(new Uri("")); + clientBuilder.UseCredential(new DefaultAzureCredential()); +}); + +using IHost host = builder.Build(); +await host.RunAsync(); diff --git a/docs/azure/sdk/snippets/dependency-injection/HostBuilder/HostBuilder.csproj b/docs/azure/sdk/snippets/dependency-injection/HostBuilder/HostBuilder.csproj new file mode 100644 index 0000000000000..aac5b5819bb1f --- /dev/null +++ b/docs/azure/sdk/snippets/dependency-injection/HostBuilder/HostBuilder.csproj @@ -0,0 +1,17 @@ + + + + net7.0 + enable + enable + dotnet-HostBuilder-3f144e50-3cf7-463d-b3e7-33f5e9a62474 + + + + + + + + + + diff --git a/docs/azure/sdk/snippets/dependency-injection/HostBuilder/Program.cs b/docs/azure/sdk/snippets/dependency-injection/HostBuilder/Program.cs new file mode 100644 index 0000000000000..5d1946a8b267c --- /dev/null +++ b/docs/azure/sdk/snippets/dependency-injection/HostBuilder/Program.cs @@ -0,0 +1,20 @@ +using HostBuilder; +#region snippet_HostBuilder +using Azure.Identity; +using Microsoft.Extensions.Azure; + +IHost host = Host.CreateDefaultBuilder(args) + .ConfigureServices(services => + { + services.AddHostedService(); + services.AddAzureClients(clientBuilder => + { + clientBuilder.AddSecretClient(new Uri("")); + clientBuilder.AddBlobServiceClient(new Uri("")); + clientBuilder.UseCredential(new DefaultAzureCredential()); + }); + }) + .Build(); + +await host.RunAsync(); +#endregion snippet_HostBuilder diff --git a/docs/azure/sdk/snippets/dependency-injection/HostBuilder/Properties/launchSettings.json b/docs/azure/sdk/snippets/dependency-injection/HostBuilder/Properties/launchSettings.json new file mode 100644 index 0000000000000..ca793456f2590 --- /dev/null +++ b/docs/azure/sdk/snippets/dependency-injection/HostBuilder/Properties/launchSettings.json @@ -0,0 +1,11 @@ +{ + "profiles": { + "HostBuilder": { + "commandName": "Project", + "dotnetRunMessages": true, + "environmentVariables": { + "DOTNET_ENVIRONMENT": "Development" + } + } + } +} diff --git a/docs/azure/sdk/snippets/dependency-injection/HostBuilder/Worker.cs b/docs/azure/sdk/snippets/dependency-injection/HostBuilder/Worker.cs new file mode 100644 index 0000000000000..a325a9cfe3086 --- /dev/null +++ b/docs/azure/sdk/snippets/dependency-injection/HostBuilder/Worker.cs @@ -0,0 +1,20 @@ +namespace HostBuilder; + +public class Worker : BackgroundService +{ + private readonly ILogger _logger; + + public Worker(ILogger logger) + { + _logger = logger; + } + + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + while (!stoppingToken.IsCancellationRequested) + { + _logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now); + await Task.Delay(1000, stoppingToken); + } + } +} diff --git a/docs/azure/sdk/snippets/dependency-injection/HostBuilder/appsettings.Development.json b/docs/azure/sdk/snippets/dependency-injection/HostBuilder/appsettings.Development.json new file mode 100644 index 0000000000000..b2dcdb67421cd --- /dev/null +++ b/docs/azure/sdk/snippets/dependency-injection/HostBuilder/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/docs/azure/sdk/snippets/dependency-injection/HostBuilder/appsettings.json b/docs/azure/sdk/snippets/dependency-injection/HostBuilder/appsettings.json new file mode 100644 index 0000000000000..60e90a1f265d7 --- /dev/null +++ b/docs/azure/sdk/snippets/dependency-injection/HostBuilder/appsettings.json @@ -0,0 +1,24 @@ +{ + "AzureDefaults": { + "Diagnostics": { + "IsTelemetryDisabled": false, + "IsLoggingContentEnabled": true + }, + "Retry": { + "MaxRetries": 3, + "Mode": "Exponential" + } + }, + "KeyVault": { + "VaultUri": "https://mykeyvault.vault.azure.net" + }, + "Storage": { + "ServiceUri": "https://mydemoaccount.storage.windows.net" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/Program.cs b/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/Program.cs new file mode 100644 index 0000000000000..e659fb734a3b3 --- /dev/null +++ b/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/Program.cs @@ -0,0 +1,50 @@ +#region snippet_WebApplicationBuilder +using Azure.Identity; +using Microsoft.Extensions.Azure; + +WebApplicationBuilder builder = WebApplication.CreateBuilder(args); + +builder.Services.AddAzureClients(clientBuilder => +{ + clientBuilder.AddSecretClient(new Uri("")); + clientBuilder.AddBlobServiceClient(new Uri("")); + clientBuilder.UseCredential(new DefaultAzureCredential()); +}); + +WebApplication app = builder.Build(); +#endregion snippet_WebApplicationBuilder + +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +string[] summaries = new[] +{ + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" +}; + +app.MapGet("/weatherforecast", () => +{ + WeatherForecast[] forecast = Enumerable.Range(1, 5).Select(index => + new WeatherForecast + ( + DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + Random.Shared.Next(-20, 55), + summaries[Random.Shared.Next(summaries.Length)] + )) + .ToArray(); + return forecast; +}) +.WithName("GetWeatherForecast") +.WithOpenApi(); + +await app.RunAsync(); + +internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) +{ + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); +} diff --git a/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/Properties/launchSettings.json b/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/Properties/launchSettings.json new file mode 100644 index 0000000000000..0ee685fbc4f02 --- /dev/null +++ b/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:24340", + "sslPort": 44314 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5038", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7117;http://localhost:5038", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/WebApplicationBuilder.csproj b/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/WebApplicationBuilder.csproj new file mode 100644 index 0000000000000..8c8344ce817d1 --- /dev/null +++ b/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/WebApplicationBuilder.csproj @@ -0,0 +1,18 @@ + + + + net7.0 + enable + enable + + + + + + + + + + + + diff --git a/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/appsettings.Development.json b/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/appsettings.Development.json new file mode 100644 index 0000000000000..0c208ae9181e5 --- /dev/null +++ b/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/appsettings.json b/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/appsettings.json new file mode 100644 index 0000000000000..c582b2771c531 --- /dev/null +++ b/docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/appsettings.json @@ -0,0 +1,25 @@ +{ + "AzureDefaults": { + "Diagnostics": { + "IsTelemetryDisabled": false, + "IsLoggingContentEnabled": true + }, + "Retry": { + "MaxRetries": 3, + "Mode": "Exponential" + } + }, + "KeyVault": { + "VaultUri": "https://mykeyvault.vault.azure.net" + }, + "Storage": { + "ServiceUri": "https://mydemoaccount.storage.windows.net" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}