Microsoft.Extensions.Azure
1.7.4
Prefix Reserved
See the version list below for details.
dotnet add package Microsoft.Extensions.Azure --version 1.7.4
NuGet\Install-Package Microsoft.Extensions.Azure -Version 1.7.4
<PackageReference Include="Microsoft.Extensions.Azure" Version="1.7.4" />
paket add Microsoft.Extensions.Azure --version 1.7.4
#r "nuget: Microsoft.Extensions.Azure, 1.7.4"
// Install Microsoft.Extensions.Azure as a Cake Addin #addin nuget:?package=Microsoft.Extensions.Azure&version=1.7.4 // Install Microsoft.Extensions.Azure as a Cake Tool #tool nuget:?package=Microsoft.Extensions.Azure&version=1.7.4
Azure client library integration for ASP.NET Core
Microsoft.Extensions.Azure provides shared primitives to integrate Azure clients with ASP.NET Core dependency injection and configuration systems.
Getting started
Install the package
Install the ASP.NET Core integration library using NuGet:
dotnet add package Microsoft.Extensions.Azure
Register clients
Make a call to AddAzureClients
in your app's ConfigureServices
method. You can use the provided builder to register client instances with your dependency injection container.
public void ConfigureServices(IServiceCollection services)
{
// Registering policy to use in ConfigureDefaults later
services.AddSingleton<DependencyInjectionEnabledPolicy>();
services.AddAzureClients(builder => {
// Register blob service client and initialize it using the KeyVault section of configuration
builder.AddSecretClient(Configuration.GetSection("KeyVault"))
// Set the name for this client registration
.WithName("NamedBlobClient")
// Set the credential for this client registration
.WithCredential(new ClientSecretCredential("<tenant_id>", "<client_id>", "<client_secret>"))
// Configure the client options
.ConfigureOptions(options => options.Retry.MaxRetries = 10);
// Adds a secret client using the provided endpoint and default credential set later
builder.AddSecretClient(new Uri("http://my.keyvault.com"));
// Configures environment credential to be used by default for all clients that require TokenCredential
// and doesn't override it on per registration level
builder.UseCredential(new EnvironmentCredential());
// This would use configuration for auth and client settings
builder.ConfigureDefaults(Configuration.GetSection("Default"));
// Configure global retry mode
builder.ConfigureDefaults(options => options.Retry.Mode = RetryMode.Exponential);
// Advanced configure global defaults
builder.ConfigureDefaults((options, provider) => options.AddPolicy(provider.GetService<DependencyInjectionEnabledPolicy>(), HttpPipelinePosition.PerCall));
// Register blob service client and initialize it using the Storage section of configuration
builder.AddBlobServiceClient(Configuration.GetSection("Storage"))
.WithVersion(BlobClientOptions.ServiceVersion.V2019_02_02);
});
}
Inject clients
To use the client request the client type from any place that supports Dependency Injection (constructors, Configure calls, @inject
razor definitions etc.)
public void Configure(IApplicationBuilder app, SecretClient secretClient, IAzureClientFactory<BlobServiceClient> blobClientFactory)
Create named instances
If client is registered as a named client inject IAzureClientFactory<T>
and call CreateClient
passing the name:
BlobServiceClient blobServiceClient = blobClientFactory.CreateClient("NamedBlobClient");
Configuration file used in the sample above:
{
"Logging": {
"LogLevel": {
"Default": "Debug"
}
},
"AllowedHosts": "*",
"Default": {
"ClientId": "<client_id>",
"ClientSecret": "<client_secret>",
"TenantId": "<tenant_id>",
"TelemetryPolicy": {
"ApplicationId": "AppId"
}
},
"KeyVault": {
"VaultUri": "<vault_uri>"
},
"Storage": {
"serviceUri": "<service_uri>",
"credential": {
"accountName": "<account_name>",
"accountKey": "<account_key>"
}
}
}
Registering a custom client factory
If you want to take control over how the client instance is created or need to use other dependencies during the client construction use the AddClient<TClient, TOptions>
method.
Here's and example of how to use IOptions<T>
instance to construct the client:
public class MyApplicationOptions
{
public Uri KeyVaultEndpoint { get; set; }
}
public void ConfigureServices(IServiceCollection services)
{
// Configure a custom options instance
services.Configure<MyApplicationOptions>(options => options.KeyVaultEndpoint = new Uri("http://localhost/"));
services.AddAzureClients(builder =>
{
// Register a client using MyApplicationOptions to get constructor parameters
builder.AddClient<SecretClient, SecretClientOptions>((options, credential, provider) =>
{
var appOptions = provider.GetService<IOptions<MyApplicationOptions>>();
return new SecretClient(appOptions.Value.KeyVaultEndpoint, credential, options);
});
});
}
Contributing
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com.
When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Azure.Core (>= 1.40.0)
- Azure.Identity (>= 1.11.4)
- Microsoft.Extensions.Configuration.Abstractions (>= 2.1.0)
- Microsoft.Extensions.Configuration.Binder (>= 2.1.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 2.1.0)
- Microsoft.Extensions.Logging.Abstractions (>= 2.1.0)
- Microsoft.Extensions.Options (>= 2.1.0)
NuGet packages (91)
Showing the top 5 NuGet packages that depend on Microsoft.Extensions.Azure:
Package | Downloads |
---|---|
Microsoft.Azure.WebJobs.Host.Storage
This package contains Azure Storage based implementations of some WebJobs SDK component interfaces. For more information, please visit https://go.microsoft.com/fwlink/?linkid=2279708. |
|
Microsoft.Azure.WebJobs.Extensions.ServiceBus
Microsoft Azure WebJobs SDK ServiceBus Extension |
|
Microsoft.Azure.WebJobs.Extensions.DurableTask
Azure WebJobs SDK Extension for the Durable Task Framework |
|
Microsoft.Azure.WebJobs.Extensions.Storage.Queues
This extension adds bindings for Storage |
|
Microsoft.Azure.WebJobs.Extensions.Storage.Blobs
This extension adds bindings for Storage |
GitHub repositories (21)
Showing the top 5 popular GitHub repositories that depend on Microsoft.Extensions.Azure:
Repository | Stars |
---|---|
dotnet/AspNetCore.Docs
Documentation for ASP.NET Core
|
|
OrchardCMS/OrchardCore
Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
|
|
Azure/azure-sdk-for-net
This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
|
|
dotnet/aspire
Tools, templates, and packages to accelerate building observable, production-ready apps
|
|
Azure/azure-functions-host
The host/runtime that powers Azure Functions
|
Version | Downloads | Last updated |
---|---|---|
1.8.0 | 23,090 | 11/5/2024 |
1.7.6 | 730,183 | 10/4/2024 |
1.7.5 | 2,086,427 | 8/15/2024 |
1.7.4 | 4,844,146 | 6/13/2024 |
1.7.3 | 5,012,467 | 4/16/2024 |
1.7.2 | 3,612,697 | 2/13/2024 |
1.7.1 | 10,838,637 | 10/27/2023 |
1.7.0 | 4,239,664 | 8/8/2023 |
1.6.3 | 17,262,855 | 3/11/2023 |
1.6.2 | 136,073 | 3/7/2023 |
1.6.0 | 10,665,891 | 10/12/2022 |
1.5.0 | 1,637,774 | 9/12/2022 |
1.4.0 | 1,077,560 | 8/12/2022 |
1.3.0 | 1,038,126 | 7/12/2022 |
1.2.0 | 9,517,835 | 5/10/2022 |
1.1.1 | 28,711,928 | 9/2/2021 |
1.1.0 | 5,073,343 | 6/9/2021 |
1.1.0-beta.3 | 9,862 | 5/11/2021 |
1.1.0-beta.2 | 334,490 | 2/8/2021 |
1.1.0-beta.1 | 63,705 | 11/6/2020 |
1.0.0 | 3,399,099 | 11/4/2019 |
1.0.0-preview.3 | 515 | 10/8/2019 |
1.0.0-preview.2 | 417 | 9/12/2019 |
1.0.0-preview.1 | 464 | 8/8/2019 |