Microsoft.Extensions.Azure     1.7.4 
                            
                                 前缀已保留
                    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 客户端库集成 ASP.NET Core
Microsoft.Extensions.Azure 提供共享原语以将 Azure 客户端与 ASP.NET Core 依赖注入 和 配置 系统集成。
入门
安装包
使用 NuGet 安装 ASP.NET Core 集成库
dotnet add package Microsoft.Extensions.Azure
注册客户端
在应用程序的 ConfigureServices 方法中调用 AddAzureClients。您可以使用提供的构建器将客户端实例注册到依赖注入容器中。
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);
    });
}
注入客户端
为了使用客户端,您可以从任何支持依赖注入(构造函数、Configure 调用、Razor 定义中的 @inject 等)的地方请求客户端类型。
public void Configure(IApplicationBuilder app, SecretClient secretClient, IAzureClientFactory<BlobServiceClient> blobClientFactory)
创建命名实例
如果客户端以命名客户端注册,则注入 IAzureClientFactory<T> 并调用 CreateClient 时传入名称
BlobServiceClient blobServiceClient = blobClientFactory.CreateClient("NamedBlobClient");
上述示例中使用的配置文件
{
  "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>"
    }
  }
}
注册自定义客户端工厂
如果您想控制客户端实例的创建方式或在客户端构造过程中使用其他依赖项,请使用 AddClient<TClient, TOptions> 方法。
以下是如何使用 IOptions<T> 实例来构建客户端的示例
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("https:///"));
    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);
        });
    });
}
贡献
本项目欢迎贡献和建议。大多数贡献都需要您同意贡献者许可协议(CLA),声明您有权并将实际将权利授予我们使用您的贡献。有关详细信息,请访问 https://cla.microsoft.com。
当您提交拉取请求时,CLA机器人将自动确定您是否需要提供CLA,并相应地标记(例如,标签或注释)拉取请求。只需按机器人提供的说明操作。您只需在整个使用我们的CLA的仓库中做一次。
本项目已采用 Microsoft 开源行为准则。有关更多信息,请参阅 行为准则常见问题解答 或通过 opencode@microsoft.com 联系我们,提出任何其他问题或意见。
| 产品 | 版本 兼容的和额外的计算目标框架版本。 | 
|---|---|
| .NET | net5.0 已计算。 net5.0-windows 已计算。 net6.0 已计算。 net6.0-android 已计算。 net6.0-ios 已计算。 net6.0-maccatalyst 已计算。 net6.0-macos 已计算。 net6.0-tvos 已计算。 net6.0-windows 已计算。 net7.0 已计算。 net7.0-android 已计算。 net7.0-ios 已计算。 net7.0-maccatalyst 已计算。 net7.0-macos 已计算。 net7.0-tvos 已计算。 net7.0-windows 已计算。 net8.0 已计算。 net8.0-android 已计算。 net8.0-browser 已计算。 net8.0-ios 已计算。 net8.0-maccatalyst 已计算。 net8.0-macos 已计算。 net8.0-tvos 已计算。 net8.0-windows 已计算。 | 
| .NET Core | netcoreapp2.0 已计算。 netcoreapp2.1 已计算。 netcoreapp2.2 已计算。 netcoreapp3.0 已计算。 netcoreapp3.1 已计算。 | 
| .NET Standard | netstandard2.0 兼容。 netstandard2.1 已计算。 | 
| .NET Framework | net461 已计算。 net462 已计算。 net463 已计算。 net47 已计算。 net471 已计算。 net472 已计算。 net48 已计算。 net481 已计算。 | 
| MonoAndroid | monoandroid 已计算。 | 
| MonoMac | monomac 已计算。 | 
| MonoTouch | monotouch 已计算。 | 
| Tizen | tizen40 已计算。 tizen60 已计算。 | 
| Xamarin.iOS | xamarinios 已计算。 | 
| Xamarin.Mac | xamarinmac 已计算。 | 
| Xamarin.TVOS | xamarintvos 已计算。 | 
| Xamarin.WatchOS | xamarinwatchos 已计算。 | 
- 
                                                    .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 包 (79)
显示依赖于 Microsoft.Extensions.Azure 的前 5 个 NuGet 包
| 包 | 下载 | 
|---|---|
| Microsoft.Azure.WebJobs.Host.Storage 此包包含基于 Azure Storage 的某些 WebJobs SDK 组件接口的实现。更多信息请访问 https://go.microsoft.com/fwlink/?linkid=2279708。 | |
| Microsoft.Azure.WebJobs.Extensions.ServiceBus 微软Azure WebJobs SDK ServiceBus扩展 | |
| Microsoft.Azure.WebJobs.Extensions.DurableTask 适用于耐久任务框架的Azure WebJobs SDK扩展 | |
| Microsoft.Azure.WebJobs.Extensions.Storage.Queues 此扩展为存储添加了绑定 | |
| Microsoft.Azure.WebJobs.Extensions.Storage.Blobs 此扩展为存储添加了绑定 | 
GitHub代码库 (18)
显示依赖于Microsoft.Extensions.Azure的前5个最受欢迎的GitHub代码库
| 代码库 | 星标 | 
|---|---|
| dotnet/AspNetCore.Docs 
                                                            ASP.NET Core文档
                                                         | |
| OrchardCMS/OrchardCore 
                                                            Orchard Core是一个使用ASP.NET Core构建的开放源码模块化和多租户应用程序框架,基于该框架构建的内容管理系统(CMS)。
                                                         | |
| Azure/azure-sdk-for-net 
                                                            此代码库用于.NET Azure SDK的积极开发。对于SDK的消费者,我们建议您访问我们的公共开发人员文档 https://learn.microsoft.com/dotnet/azure/ 或我们的版本化开发人员文档 https://azure.github.io/azure-sdk-for-net。
                                                         | |
| dotnet/aspire 
                                                            云就绪堆栈,用于在.NET中构建可观察、生产就绪、分布式应用程序
                                                         | |
| Azure/azure-functions-host 
                                                            为Azure Functions提供动力的主机/运行时
                                                         | 
| 版本 | 下载 | 最后更新 | 
|---|---|---|
| 1.7.4 | 1,375,706 | 6/13/2024 | 
| 1.7.3 | 3,036,744 | 4/16/2024 | 
| 1.7.2 | 2,719,431 | 2/13/2024 | 
| 1.7.1 | 8,586,172 | 10/27/2023 | 
| 1.7.0 | 3,739,002 | 8/8/2023 | 
| 1.6.3 | 14,946,352 | 3/11/2023 | 
| 1.6.2 | 129,690 | 3/7/2023 | 
| 1.6.0 | 10,019,069 | 10/12/2022 | 
| 1.5.0 | 1,493,233 | 9/12/2022 | 
| 1.4.0 | 1,040,097 | 8/12/2022 | 
| 1.3.0 | 990,763 | 7/12/2022 | 
| 1.2.0 | 9,052,453 | 5/10/2022 | 
| 1.1.1 | 26,432,146 | 9/2/2021 | 
| 1.1.0 | 4,508,307 | 6/9/2021 | 
| 1.1.0-beta.3 | 9,603 | 5/11/2021 | 
| 1.1.0-beta.2 | 329,676 | 2/8/2021 | 
| 1.1.0-beta.1 | 63,502 | 11/6/2020 | 
| 1.0.0 | 3,292,378 | 11/4/2019 | 
| 1.0.0-preview.3 | 492 | 10/8/2019 | 
| 1.0.0-preview.2 | 395 | 9/12/2019 | 
| 1.0.0-preview.1 | 431 | 8/8/2019 |