This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
Includes: Hosting integration only —
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.
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.DataApiBuilderFor more information, seedotnet add package orManage package dependencies in .NET applications.
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.
| Parameter | Description |
|---|---|
name | The name of the resource is a requiredstring and it's validated by theResourceNameAttribute. |
configFilePaths | The 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". |
httpPort | The 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. |
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");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>')",}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.
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?