Skip to content

Commit 05b444f

Browse files
JamesNKIEvangelist
andauthored
[9.1] Add resource relationship docs (#2637)
* Add resource relationship docs * Fix linter * Update * Update * Update * Update * Apply suggestions from code review --------- Co-authored-by: David Pine <[email protected]>
1 parent fe61b99 commit 05b444f

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

docs/fundamentals/app-host-overview.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,37 @@ This logic can easily be inverted to connect to an existing Redis resource when
488488
> [!IMPORTANT]
489489
> .NET Aspire provides common APIs to control the modality of resource builders, allowing resources to behave differently based on the execution mode. The fluent APIs are prefixed with `RunAs*` and `PublishAs*`. The `RunAs*` APIs influence the local development (or run mode) behavior, whereas the `PublishAs*` APIs influence the publishing of the resource.
490490
491+
## Resource relationships
492+
493+
Resource relationships link resources together. Relationships are informational and don't impact an app's runtime behavior. Instead, they're used when displaying details about resources in the dashboard. For example, relationships are visible in the [dashboard's resource details](./dashboard/explore.md#resource-details), and `Parent` relationships control resource nesting on the resources page.
494+
495+
Relationships are automatically created by some app model APIs. For example:
496+
497+
- <xref:Aspire.Hosting.ResourceBuilderExtensions.WithReference*> adds a relationship to the target resource with the type `Reference`.
498+
- <xref:Aspire.Hosting.ResourceBuilderExtensions.WaitFor*> adds a relationship to the target resource with the type `WaitFor`.
499+
- Adding a database to a DB container creates a relationship from the database to the container with the type `Parent`.
500+
501+
Relationships can also be explicitly added to the app model using `WithRelationship` and `WithParentRelationship`.
502+
503+
```csharp
504+
var builder = DistributedApplication.CreateBuilder(args);
505+
506+
var catalogDb = builder.AddPostgres("postgres")
507+
.WithDataVolume()
508+
.AddDatabase("catalogdb");
509+
510+
builder.AddProject<Projects.AspireApp_CatalogDbMigration>("migration")
511+
.WithReference(catalogDb)
512+
.WithParentRelationship(catalogDb);
513+
514+
builder.Build().Run();
515+
```
516+
517+
The preceding example uses `WithParentRelationship` to configure `catalogdb` database as the `migration` project's parent. The `Parent` relationship is special because it controls resource nesting on the resource page. In this example, `migration` is nested under `catalogdb`.
518+
519+
> [!NOTE]
520+
> There's validation for parent relationships to prevent a resource from having multiple parents or creating a circular reference. These configurations can't be rendered in the UI, and the app model will throw an error.
521+
491522
## See also
492523

493524
- [.NET Aspire integrations overview](integrations-overview.md)

0 commit comments

Comments
 (0)