-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Update Azure SDK DI doc for additional app builders #36298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2a7f088
Update Azure SDK DI doc for additional app builder
scottaddie c428f6d
Update section link
scottaddie 287495f
Terminate tab group and fix code sample
scottaddie c40ecc1
More improvements
scottaddie c1824bf
Update line numbers
scottaddie bb84aa7
Add HostBuilder code sample
scottaddie 1a7bb63
Update code sample
scottaddie f1d94a1
More edits
scottaddie 9469d76
Update JSON sample
scottaddie 059bbcc
Code formatting to prevent horizontal scrolling
scottaddie c5216ec
Link to client registration section
scottaddie fff26bb
Wrap long lines of code
scottaddie 992ff04
Shorten API xref link
scottaddie bd38c7a
Remove duplicate package install commands
scottaddie e6522d9
Add explanation of AzureDefaults section name
scottaddie 5537217
React to Alex's feedback
scottaddie 15d3904
Update verbiage
scottaddie b58bec7
Add more clarity
scottaddie 80e3224
Simplify Program.cs
scottaddie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
docs/azure/sdk/snippets/dependency-injection/Directory.Packages.props
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <Project> | ||
| <PropertyGroup> | ||
| <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageVersion Include="Azure.Identity" Version="1.9.0" /> | ||
| <PackageVersion Include="Azure.Security.KeyVault.Secrets" Version="4.5.0" /> | ||
| <PackageVersion Include="Azure.Storage.Blobs" Version="12.17.0" /> | ||
| <PackageVersion Include="Microsoft.Extensions.Azure" Version="1.6.3" /> | ||
| <PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="7.0.9" /> | ||
| <PackageVersion Include="Microsoft.Extensions.Hosting" Version="7.0.1" /> | ||
| <PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" /> | ||
| </ItemGroup> | ||
| </Project> |
17 changes: 17 additions & 0 deletions
17
...re/sdk/snippets/dependency-injection/HostApplicationBuilder/HostApplicationBuilder.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net7.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Azure.Identity" /> | ||
| <PackageReference Include="Azure.Security.KeyVault.Secrets" /> | ||
| <PackageReference Include="Azure.Storage.Blobs" /> | ||
| <PackageReference Include="Microsoft.Extensions.Azure" /> | ||
| <PackageReference Include="Microsoft.Extensions.Hosting" /> | ||
| </ItemGroup> | ||
| </Project> |
15 changes: 15 additions & 0 deletions
15
docs/azure/sdk/snippets/dependency-injection/HostApplicationBuilder/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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("<key_vault_url>")); | ||
| clientBuilder.AddBlobServiceClient(new Uri("<storage_url>")); | ||
| clientBuilder.UseCredential(new DefaultAzureCredential()); | ||
| }); | ||
|
|
||
| using IHost host = builder.Build(); | ||
| await host.RunAsync(); |
17 changes: 17 additions & 0 deletions
17
docs/azure/sdk/snippets/dependency-injection/HostBuilder/HostBuilder.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Worker"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net7.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <UserSecretsId>dotnet-HostBuilder-3f144e50-3cf7-463d-b3e7-33f5e9a62474</UserSecretsId> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Azure.Identity" /> | ||
| <PackageReference Include="Azure.Security.KeyVault.Secrets" /> | ||
| <PackageReference Include="Azure.Storage.Blobs" /> | ||
| <PackageReference Include="Microsoft.Extensions.Azure" /> | ||
| <PackageReference Include="Microsoft.Extensions.Hosting" /> | ||
| </ItemGroup> | ||
| </Project> |
20 changes: 20 additions & 0 deletions
20
docs/azure/sdk/snippets/dependency-injection/HostBuilder/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<Worker>(); | ||
| services.AddAzureClients(clientBuilder => | ||
| { | ||
| clientBuilder.AddSecretClient(new Uri("<key_vault_url>")); | ||
| clientBuilder.AddBlobServiceClient(new Uri("<storage_url>")); | ||
| clientBuilder.UseCredential(new DefaultAzureCredential()); | ||
| }); | ||
| }) | ||
| .Build(); | ||
|
|
||
| await host.RunAsync(); | ||
| #endregion snippet_HostBuilder |
11 changes: 11 additions & 0 deletions
11
docs/azure/sdk/snippets/dependency-injection/HostBuilder/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| { | ||
| "profiles": { | ||
| "HostBuilder": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "environmentVariables": { | ||
| "DOTNET_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
docs/azure/sdk/snippets/dependency-injection/HostBuilder/Worker.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| namespace HostBuilder; | ||
|
|
||
| public class Worker : BackgroundService | ||
| { | ||
| private readonly ILogger<Worker> _logger; | ||
|
|
||
| public Worker(ILogger<Worker> 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); | ||
| } | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
docs/azure/sdk/snippets/dependency-injection/HostBuilder/appsettings.Development.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.Hosting.Lifetime": "Information" | ||
| } | ||
| } | ||
| } |
24 changes: 24 additions & 0 deletions
24
docs/azure/sdk/snippets/dependency-injection/HostBuilder/appsettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| } | ||
| } |
50 changes: 50 additions & 0 deletions
50
docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/Program.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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("<key_vault_url>")); | ||
| clientBuilder.AddBlobServiceClient(new Uri("<storage_url>")); | ||
| clientBuilder.UseCredential(new DefaultAzureCredential()); | ||
| }); | ||
|
|
||
| WebApplication app = builder.Build(); | ||
| #endregion snippet_WebApplicationBuilder | ||
|
|
||
| if (app.Environment.IsDevelopment()) | ||
| { | ||
| app.UseSwagger(); | ||
scottaddie marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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); | ||
| } | ||
41 changes: 41 additions & 0 deletions
41
...re/sdk/snippets/dependency-injection/WebApplicationBuilder/Properties/launchSettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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" | ||
| } | ||
| } | ||
| } | ||
| } |
18 changes: 18 additions & 0 deletions
18
...zure/sdk/snippets/dependency-injection/WebApplicationBuilder/WebApplicationBuilder.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net7.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Azure.Identity" /> | ||
| <PackageReference Include="Azure.Security.KeyVault.Secrets" /> | ||
| <PackageReference Include="Azure.Storage.Blobs" /> | ||
| <PackageReference Include="Microsoft.Extensions.Azure" /> | ||
| <PackageReference Include="Microsoft.AspNetCore.OpenApi" /> | ||
| <PackageReference Include="Swashbuckle.AspNetCore" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
8 changes: 8 additions & 0 deletions
8
...zure/sdk/snippets/dependency-injection/WebApplicationBuilder/appsettings.Development.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
25 changes: 25 additions & 0 deletions
25
docs/azure/sdk/snippets/dependency-injection/WebApplicationBuilder/appsettings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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": "*" | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.