इसे छोड़कर कंटेंट पर जाएं

Azure Table Storage - Client integration

यह कंटेंट अभी तक आपकी भाषा में उपलब्ध नहीं है।

To get started with the Aspire Azure Table Storage client integration, install the 📦 Aspire.Azure.Data.Tables NuGet package:

.NET CLI — Add Aspire.Azure.Data.Tables package
dotnet add package Aspire.Azure.Data.Tables

In the Program.cs file of your client-consuming project, call the AddAzureTableServiceClient extension method to register a TableServiceClient for dependency injection. The method takes a connection name parameter:

builder.AddAzureTableServiceClient("tables");

You can then retrieve the TableServiceClient instance using dependency injection:

public class ExampleService(TableServiceClient client)
{
// Use client...
}

Properties of the Azure Table Storage resources

Section titled “Properties of the Azure Table Storage resources”

When you use the WithReference method to pass an Azure Table Storage resource from the AppHost project to a consuming client project, several properties are available to use in the consuming project.

Aspire exposes each property as an environment variable named [RESOURCE]_[PROPERTY]. For instance, the Uri property of a resource called tables becomes TABLES_URI.

The Azure Table Storage resource exposes the following connection properties:

Property NameDescription
UriThe table service endpoint

In emulator mode, an additional property is available:

Property NameDescription
ConnectionStringThe full connection string for the emulator

For example, if you reference a Table Storage resource named tables in your AppHost project, the following environment variables will be available in the consuming project:

  • TABLES_URI

The Azure Table Storage integration provides multiple options to configure the TableServiceClient.

The Azure Table Storage integration supports Microsoft.Extensions.Configuration. It loads the AzureDataTablesSettings and TableClientOptions from configuration using the Aspire:Azure:Data:Tables key. Example appsettings.json:

{
"Aspire": {
"Azure": {
"Data": {
"Tables": {
"ServiceUri": "YOUR_URI",
"DisableHealthChecks": true,
"DisableTracing": false,
"ClientOptions": {
"EnableTenantDiscovery": true
}
}
}
}
}
}

The Azure Table Storage integration supports named configuration for multiple instances:

{
"Aspire": {
"Azure": {
"Data": {
"Tables": {
"tables1": {
"ServiceUri": "https://myaccount1.table.core.windows.net/",
"DisableHealthChecks": true,
"ClientOptions": {
"EnableTenantDiscovery": true
}
},
"tables2": {
"ServiceUri": "https://myaccount2.table.core.windows.net/",
"DisableTracing": true,
"ClientOptions": {
"EnableTenantDiscovery": false
}
}
}
}
}
}
}

Use the connection names when calling AddAzureTableServiceClient:

builder.AddAzureTableServiceClient("tables1");
builder.AddAzureTableServiceClient("tables2");

You can also pass the Action<AzureDataTablesSettings> delegate to set up options inline:

builder.AddAzureTableServiceClient(
"tables",
settings => settings.DisableHealthChecks = true);

You can also configure the TableClientOptions:

builder.AddAzureTableServiceClient(
"tables",
configureClientBuilder: clientBuilder =>
clientBuilder.ConfigureOptions(
options => options.EnableTenantDiscovery = true));

By default, Aspire integrations enable health checks for all services. The Azure Table Storage integration:

  • Adds the health check when DisableHealthChecks is false, which attempts to connect to the Azure Table Storage.
  • Integrates with the /health HTTP endpoint, which specifies all registered health checks must pass for app to be considered ready to accept traffic.

The Azure Table Storage integration uses the following log categories:

  • Azure.Core
  • Azure.Identity

The Azure Table Storage integration emits the following tracing activities using OpenTelemetry:

  • Azure.Data.Tables.TableServiceClient

The Azure Table Storage integration currently doesn’t support metrics by default due to limitations with the Azure SDK.