Skip to content

Support deep-linking to child resources in CosmosDB, EventHubs, ServiceBus #7907

@eerhardt

Description

@eerhardt

The next step after EventHubs, ServiceBus, and CosmosDB Hosting integrations should create Resources for children (dotnet/aspire#7407) is that we should support "deep linking" to the child resources and have corresponding client integration APIs for adding the child directly.

For example, in CosmosDB:

AppHost

var cosmos = builder.AddAzureCosmosDB("cosmos")
                .RunAsPreviewEmulator(e => e.WithDataExplorer());

var db = cosmos.AddCosmosDatabase("db");
var entries = db.AddContainer("entries", "/id");

builder.AddProject<Projects.CosmosEndToEnd_ApiService>("api")
       .WithExternalHttpEndpoints()
       .WithReference(cosmos) // adds 'cosmos' connection string pointing to root service
       .WithReference(db) // adds 'db' connection string pointing to the root service + ";Database=db"
       .WithReference(entries); // adds 'entries' connection string pointing to the root service + ";Database=db" + ";Container=entries"

Then on the app side, we should have corresponding APIs for directly referencing these children:

builder.AddAzureCosmosClient("cosmos"); // exists today
builder.AddAzureCosmosDatabaseClient("db"); // new, registers a Microsoft.Azure.Cosmos.Database in DI
builder.AddAzureCosmosContainerClient("entries"); // new, registers a Microsoft.Azure.Cosmos.Container in DI

On CosmosDB EF, this will simply the existing code:

builder.AddCosmosDbContext<TestCosmosContext>("cosmos", "db"); // today
builder.AddCosmosDbContext<TestCosmosContext>("db"); // new - gets all connection information from the 'db' connection string

QUESTION: What happens if you AddCosmosDbContext to a "container"? Today AFAIK EF defaults to using the DbContext TypeName as the container name. Maybe we can change that to the specified container if you deep-link to that container.

We should do similar APIs for EventHubs and ServiceBus as well, where it makes sense.

We should also remember to update the Azure Functions config support as well.

Resource Types Requiring Support

Metadata

Metadata

Assignees

Labels

area-integrationsIssues pertaining to Aspire Integrations packagesazureIssues associated specifically with scenarios tied to using Azure

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions