Movatterモバイル変換


[0]ホーム

URL:


Skip to main content

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Download Microsoft EdgeMore info about Internet Explorer and Microsoft Edge
Table of contentsExit editor mode

Community Toolkit Azure Data API Builder hosting integration

Feedback

In this article

Includes:Hosting integration included Hosting integration only —Client integration not included Client integration not included

Note

This integration is part of theAspire Community Toolkit andisn't officially supported by the Aspire team.

In this article, you learn how to use the Aspire Data API Builder hosting integration to runData API Builder as a container.

Hosting integration

To get started with the Aspire Azure Data API Builder hosting integration, install the📦 CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder NuGet package in theAppHost project.

dotnet add package CommunityToolkit.Aspire.Hosting.Azure.DataApiBuilder

For more information, seedotnet add package orManage package dependencies in .NET applications.

Usage

In the AppHost project, register and consume the Data API Builder integration using theAddDataAPIBuilder extension method to add the Data API Builder container to the application builder.

 var builder = DistributedApplication.CreateBuilder(); // Add Data API Builder using dab-config.json var dab = builder.AddDataAPIBuilder("dab");builder.AddProject<Projects.ExampleProject>()         .WithReference(dab);  // After adding all resources, run the app...

When the Aspire adds a container image to the AppHost, as shown in the preceding example with themcr.microsoft.com/azure-databases/data-api-builder image, it creates a new Data API Builder instance on your local machin. A reference to the DAB resource (thedab variable) is added to theExampleProject project.

Configuration

ParameterDescription
nameThe name of the resource is a requiredstring and it's validated by theResourceNameAttribute.
configFilePathsThe paths to the configuration or schema file(s) for Data API builder. These are optional and are available as aparams string[], meaning you can omit them altogether, or provide one or more path inline. When omitted, it defaults to"./dab-config.json".
httpPortThe port number for the Data API Builder container is represented as a anint?. By default, the port isnull, Aspire assigns a port when this isn't otherwise provided.

Data API Builder container image configuration

You can specify custom containerregistry/image/tag values by using the following APIs chained to theIResourceBuilder<DataApiBuilderContainerResource>:

  • WithImageRegistry: Pass the desired registry name, such asghcr.io for the GitHub Container Registry ordocker.io for Docker.
  • WithImage: Provide the name of the image, such asazure-databases/data-api-builder.
  • WithImageTag: Specify an image tag to use other thanlatest, which is the default in most cases.

Consider the following example that demonstrates chaining these APIs together, to fluently express that the Data API Builder's container image is fully qualified asmcr.microsoft.com/azure-databases/data-api-builder:latest:

var dab = builder.AddDataAPIBuilder("dab")    .WithImageRegistry("mcr.microsoft.com")    .WithImage("azure-databases/data-api-builder")    .WithImageTag("latest");

Database Configuration

If you need to configure your own local database, you can refer to theSQL Server integration documentation.

Once you have your database added as a resource, you can reference it using the following APIs chained to theIResourceBuilder<DataApiBuilderContainerResource>:

var dab = builder.AddDataAPIBuilder("dab")    .WithReference(sqlDatabase)    .WaitFor(sqlDatabase);

TheWaitFor method ensures that the database is ready before starting the Data API Builder container.

Referencing thesqlDatabase resource will inject its connection string into the Data API Builder container with the nameConnectionStrings__<DATABASE_RESOURCE_NAME>.Next, update thedab-config.json file to include the connection string for the database:

"data-source": {    "connection-string": "@env('ConnectionStrings__<DATABASE_RESOURCE_NAME>')",}

Using multiple data sources

You can pass multiple configuration files to theAddDataAPIBuilder method:

var dab = builder.AddDataAPIBuilder("dab",         "./dab-config-1.json",         "./dab-config-2.json")    .WithReference(sqlDatabase1)    .WaitFor(sqlDatabase1)    .WithReference(sqlDatabase2)    .WaitFor(sqlDatabase2);

Note

All files are mounted/copied to the same/App folder.

See also

Collaborate with us on GitHub
The source for this content can be found on GitHub, where you can also create and review issues and pull requests. For more information, seeour contributor guide.

Feedback

Was this page helpful?

YesNoNo

Need help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?

  • Last updated on

In this article

Was this page helpful?

YesNo
NoNeed help with this topic?

Want to try using Ask Learn to clarify or guide you through this topic?

Suggest a fix?