.NET Aspire Azure Data Tables integration

In this article, you learn how to use the .NET Aspire Azure Data Tables integration. The Aspire.Azure.Data.Tables library is used to:

  • Registers a TableServiceClient as a singleton in the DI container for connecting to Azure Table storage.
  • Enables corresponding health checks, logging and telemetry.

Prerequisites

Get started

To get started with the .NET Aspire Azure Data Tables integration, install the Aspire.Azure.Data.Tables NuGet package in the client-consuming project, i.e., the project for the application that uses the Azure Data Tables client.

dotnet add package Aspire.Azure.Data.Tables

For more information, see dotnet add package or Manage package dependencies in .NET applications.

Example usage

In the Program.cs file of your integration-consuming project, call the AddAzureTableClient extension to register a TableServiceClient for use via the dependency injection container.

builder.AddAzureTableClient("tables");

To retrieve the TableServiceClient instance using dependency injection, define it as a constructor parameter. Consider the following example service:

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

App host usage

To add Azure Storage hosting support to your IDistributedApplicationBuilder, install the Aspire.Hosting.Azure.Storage NuGet package in the app host project.

dotnet add package Aspire.Hosting.Azure.Storage

In your app host project, register the Azure Table Storage integration and consume the service using the following methods:

var builder = DistributedApplication.CreateBuilder(args);

var tables = builder.AddAzureStorage("storage")
                    .AddTables("tables");

Builder.AddProject<MyApp.ExampleProject>() 
       .WithReference(tables)

For more information, see WithReference.

Configuration

The .NET Aspire Azure Table Storage integration provides multiple options to configure the TableServiceClient based on the requirements and conventions of your project.

Use configuration providers

The .NET Aspire Azure Table Storage integration supports Microsoft.Extensions.Configuration. It loads the AzureDataTablesSettings from appsettings.json or other configuration files using Aspire:Azure:Data:Tables key.

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

If you have set up your configurations in the Aspire:Azure:Data:Tables section of your appsettings.json file you can just call the method AddAzureTableClient without passing any parameters.

Use inline delegates

You can also pass the Action<AzureDataTablesSettings> delegate to set up some or all the options inline, for example to set the ServiceUri:

builder.AddAzureTableClient(
    "tables",
    static settings => settings.ServiceUri = new Uri("YOUR_SERVICEURI"));

You can also set up the TableClientOptions using Action<IAzureClientBuilder<TableServiceClient, TableClientOptions>> delegate, the second parameter of the AddAzureTableClient method. For example to set the TableServiceClient ID to identify the client:

builder.AddAzureTableClient(
    "tables",
    static clientBuilder =>
        clientBuilder.ConfigureOptions(
            static options => options.EnableTenantDiscovery = true));

Configuration options

The following configurable options are exposed through the AzureDataTablesSettings class:

Name Description
ServiceUri A "Uri" referencing the Table service.
Credential The credential used to authenticate to the Table Storage.
DisableHealthChecks A boolean value that indicates whether the Table Storage health check is disabled or not.
DisableTracing A boolean value that indicates whether the OpenTelemetry tracing is disabled or not.

Health checks

By default, .NET Aspire integrations enable health checks for all services. For more information, see .NET Aspire integrations overview.

By default, The .NET Aspire Azure Data Tables integration handles the following:

  • Adds the AzureTableStorageHealthCheck health check, which attempts to connect to and query 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

Observability and telemetry

.NET Aspire integrations automatically set up Logging, Tracing, and Metrics configurations, which are sometimes known as the pillars of observability. For more information about integration observability and telemetry, see .NET Aspire integrations overview. Depending on the backing service, some integrations may only support some of these features. For example, some integrations support logging and tracing, but not metrics. Telemetry features can also be disabled using the techniques presented in the Configuration section.

Logging

The .NET Aspire Azure Data Tables integration uses the following log categories:

  • Azure.Core
  • Azure.Identity

Tracing

The .NET Aspire Azure Data Tables integration will emit the following tracing activities using OpenTelemetry:

  • "Azure.Data.Tables.TableServiceClient"

Metrics

The .NET Aspire Azure Data Tables integration currently does not support metrics by default due to limitations with the Azure SDK.

See also