gpt4 book ai didi

c# - 创建和处置 SecretClient

转载 作者:行者123 更新时间:2023-12-02 23:35:40 25 4
gpt4 key购买 nike

如何从 Azure.Security.KeyVault.Secrets 创建和处置 SecretClient?我正在从 KeyVaultClient 迁移,但似乎找不到太多相关文档。

最佳答案

有一篇非常好的文章解释了 Azure SDK 的客户端如何工作 - Lifetime management for Azure SDK .NET clients :

  • Client lifetime: The main rule of Azure SDK client lifetime management is: treat clients as singletons.
  • Thread-safety: Clients are thread-safe. Models are not thread-safe.
  • Clients are immutable
  • Clients are not disposable: Shared HttpClient as default: One question that comes up often is why aren’t HTTP-based Azure clients implementing IDisposable while internally using an HttpClient that is disposable? All Azure SDK clients, by default, use a single shared HttpClient instance and don’t create any other resources that need to be actively freed. The shared client instance persists throughout the entire application lifetime.

来自Azure Key Vault secret client library for .NET ,有很多关于如何使用新客户端的示例:

// Create a new secret client using the default credential from Azure.Identity using environment variables previously set,
// including AZURE_CLIENT_ID, AZURE_CLIENT_SECRET, and AZURE_TENANT_ID.
var client = new SecretClient(vaultUri: new Uri(vaultUrl), credential: new DefaultAzureCredential());

// Create a new secret using the secret client.
KeyVaultSecret secret = client.SetSecret("secret-name", "secret-value");

// Retrieve a secret using the secret client.
secret = client.GetSecret("secret-name");

关于c# - 创建和处置 SecretClient,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72896555/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com