Class KeyVaultService
Service that handles the Azure Key Vault integration. A singleton instance of this class is registered in the service collection.
public sealed class KeyVaultService : IKeyVaultService
- Inheritance
-
KeyVaultService
- Implements
- Inherited Members
Remarks
Constructor.
Constructors
KeyVaultService(IOptionsMonitor<AzureOptions>)
Service that handles the Azure Key Vault integration. A singleton instance of this class is registered in the service collection.
public KeyVaultService(IOptionsMonitor<AzureOptions> options)
Parameters
options
IOptionsMonitor<AzureOptions>The configuration instance used to retrieve the Azure Key Vault URI.
Remarks
Constructor.
Exceptions
- ArgumentNullException
Thrown when the configuration is null.
Properties
_secretClient
private SecretClient _secretClient { get; init; }
Property Value
Exceptions
- ArgumentNullException
Thrown when the configuration is null.
Methods
TryGetSecret(string)
Fetches a Key Vault secret by name synchronously. When using this method, the thread will be blocked until the secret is fetched. For asynchronous fetching, use the TryGetSecretAsync(string) method.
public string TryGetSecret(string secretName)
Parameters
secretName
stringThe name of the secret to fetch from Azure Key Vault.
Returns
- string
The value of the secret.
Exceptions
- Exception
Thrown when the retrieval of the secret fails.
TryGetSecretAsync(string)
Fetches a Key Vault secret by name asynchronously. When using this method, the thread will not be blocked until the secret is fetched. For synchronous fetching, use the TryGetSecret(string) method.
public Task<string> TryGetSecretAsync(string secretName)
Parameters
secretName
stringThe name of the secret to fetch from Azure Key Vault.
Returns
- Task<string>
A task representing the asynchronous operation. The result of the task is the value of the secret.
Exceptions
- Exception
Thrown when the retrieval of the secret fails.