Skip to content

Commit 5f64169

Browse files
Merge pull request #3506 from dotnet/main
✅ Merge `main` into `live`
2 parents 077497a + 77c03c3 commit 5f64169

File tree

148 files changed

+11073
-145
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+11073
-145
lines changed

.openpublishing.redirection.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,10 @@
283283
{
284284
"source_path_from_root": "/docs/deployment/azure/local-provisioning.md",
285285
"redirect_url": "/dotnet/aspire/azure/local-provisioning"
286+
},
287+
{
288+
"source_path_from_root": "/docs/frameworks/dapr.md",
289+
"redirect_url": "/dotnet/aspire/azure/dapr"
286290
}
287291
]
288292
}

docs/app-host/configuration.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ By default, the dashboard is automatically started by the app host. The dashboar
7777
| `ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL` | `null` | Configures the dashboard OTLP HTTP address. Used by the dashboard to receive telemetry over OTLP. If only `ASPIRE_DASHBOARD_OTLP_HTTP_ENDPOINT_URL` is configured then it is set on resources as the `OTEL_EXPORTER_OTLP_ENDPOINT` env var. The `OTEL_EXPORTER_OTLP_PROTOCOL` env var is `http/protobuf`. |
7878
| `ASPIRE_DASHBOARD_CORS_ALLOWED_ORIGINS` | `null` | Overrides the CORS allowed origins configured in the dashboard. This setting replaces the default behavior of calculating allowed origins based on resource endpoints. |
7979
| `ASPIRE_DASHBOARD_FRONTEND_BROWSERTOKEN` | Automatically generated 128-bit entropy token. | Configures the frontend browser token. This is the value that must be entered to access the dashboard when the auth mode is BrowserToken. If no browser token is specified then a new token is generated each time the app host is launched. |
80+
| `ASPIRE_DASHBOARD_TELEMETRY_OPTOUT` | `false` | Configures the dashboard to never send [usage telemetry](../fundamentals/dashboard/microsoft-collected-dashboard-telemetry.md). |
81+
| `ASPIRE_DASHBOARD_AI_DISABLED` | `false` | [GitHub Copilot in the dashboard](../fundamentals/dashboard/copilot.md) is available when the app host is launched by a supported IDE. When set to `true` Copilot is disabled in the dashboard and no Copilot UI is visible. |
8082

8183
## Internal
8284

docs/app-host/eventing.md

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,21 @@ All of the preceding events are analogous to the [app host life cycles](xref:dot
2626

2727
To subscribe to the built-in app host events, use the eventing API. After you have a distributed application builder instance, walk up to the <xref:Aspire.Hosting.IDistributedApplicationBuilder.Eventing?displayProperty=nameWithType> property and call the <xref:Aspire.Hosting.Eventing.IDistributedApplicationEventing.Subscribe``1(System.Func{``0,System.Threading.CancellationToken,System.Threading.Tasks.Task})> API. Consider the following sample app host _Program.cs_ file:
2828

29-
:::code source="snippets/AspireApp/AspireApp.AppHost/Program.cs" highlight="17-25,27-35,37-45":::
29+
:::code source="snippets/AspireApp/AspireApp.AppHost/Program.cs":::
3030

3131
The preceding code is based on the starter template with the addition of the calls to the `Subscribe` API. The `Subscribe<T>` API returns a <xref:Aspire.Hosting.Eventing.DistributedApplicationEventSubscription> instance that you can use to unsubscribe from the event. It's common to discard the returned subscriptions, as you don't usually need to unsubscribe from events as the entire app is torn down when the app host is shut down.
3232

3333
When the app host is run, by the time the .NET Aspire dashboard is displayed, you should see the following log output in the console:
3434

35-
:::code language="Plaintext" source="snippets/AspireApp/AspireApp.AppHost/Console.txt" highlight="2,10,16":::
35+
:::code language="Plaintext" source="snippets/AspireApp/AspireApp.AppHost/Console.txt" highlight="2,10-14,20":::
3636

37-
The log output confirms that event handlers are executed in the order of the app host life cycle events. The subscription order doesn't affect execution order. The `BeforeStartEvent` is triggered first, followed by `AfterEndpointsAllocatedEvent`, and finally `AfterResourcesCreatedEvent`.
37+
The log output confirms that event handlers are executed in the order of the app host life cycle events. The subscription order doesn't affect execution order. The `BeforeStartEvent` is triggered first, followed by `AfterEndpointsAllocatedEvent`, then each resource has its `ResourceEndpointsAllocatedEvent` event fired, and finally `AfterResourcesCreatedEvent`.
3838

3939
## Resource eventing
4040

4141
In addition to the app host events, you can also subscribe to resource events. Resource events are raised specific to an individual resource. Resource events are defined as implementations of the <xref:Aspire.Hosting.Eventing.IDistributedApplicationResourceEvent> interface. The following resource events are available in the listed order:
4242

43+
1. `InitializeResourceEvent`: Raised by orchestrators to signal to resources that they should initialize themselves.
4344
1. <xref:Aspire.Hosting.ApplicationModel.ConnectionStringAvailableEvent>: Raised when a connection string becomes available for a resource.
4445
1. <xref:Aspire.Hosting.ApplicationModel.BeforeResourceStartedEvent>: Raised before the orchestrator starts a new resource.
4546
1. <xref:Aspire.Hosting.ApplicationModel.ResourceReadyEvent>: Raised when a resource initially transitions to a ready state.
@@ -48,13 +49,13 @@ In addition to the app host events, you can also subscribe to resource events. R
4849

4950
To subscribe to resource events, use the eventing API. After you have a distributed application builder instance, walk up to the <xref:Aspire.Hosting.IDistributedApplicationBuilder.Eventing?displayProperty=nameWithType> property and call the <xref:Aspire.Hosting.Eventing.IDistributedApplicationEventing.Subscribe``1(Aspire.Hosting.ApplicationModel.IResource,System.Func{``0,System.Threading.CancellationToken,System.Threading.Tasks.Task})> API. Consider the following sample app host _Program.cs_ file:
5051

51-
:::code source="snippets/AspireApp/AspireApp.ResourceAppHost/Program.cs" highlight="8-17,19-28,30-39":::
52+
:::code source="snippets/AspireApp/AspireApp.ResourceAppHost/Program.cs":::
5253

53-
The preceding code subscribes to the `ResourceReadyEvent`, `ConnectionStringAvailableEvent`, and `BeforeResourceStartedEvent` events on the `cache` resource. When <xref:Aspire.Hosting.RedisBuilderExtensions.AddRedis*> is called, it returns an <xref:Aspire.Hosting.ApplicationModel.IResourceBuilder`1> where `T` is a <xref:Aspire.Hosting.ApplicationModel.RedisResource>. The resource builder exposes the resource as the <xref:Aspire.Hosting.ApplicationModel.IResourceBuilder`1.Resource?displayProperty=nameWithType> property. The resource in question is then passed to the `Subscribe` API to subscribe to the events on the resource.
54+
The preceding code subscribes to the `InitializeResourceEvent`, `ResourceReadyEvent`, `ConnectionStringAvailableEvent`, and `BeforeResourceStartedEvent` events on the `cache` resource. When <xref:Aspire.Hosting.RedisBuilderExtensions.AddRedis*> is called, it returns an <xref:Aspire.Hosting.ApplicationModel.IResourceBuilder`1> where `T` is a <xref:Aspire.Hosting.ApplicationModel.RedisResource>. The resource builder exposes the resource as the <xref:Aspire.Hosting.ApplicationModel.IResourceBuilder`1.Resource?displayProperty=nameWithType> property. The resource in question is then passed to the `Subscribe` API to subscribe to the events on the resource.
5455

5556
When the app host is run, by the time the .NET Aspire dashboard is displayed, you should see the following log output in the console:
5657

57-
:::code language="Plaintext" source="snippets/AspireApp/AspireApp.ResourceAppHost/Console.txt" highlight="8,10,12":::
58+
:::code language="Plaintext" source="snippets/AspireApp/AspireApp.ResourceAppHost/Console.txt" highlight="8,10,12,18":::
5859

5960
> [!NOTE]
6061
> Some events are blocking. For example, when the `BeforeResourceStartEvent` is published, the startup of the resource will be blocked until all subscriptions for that event on a given resource have completed executing. Whether an event is blocking or not depends on how it is published (see the following section).
@@ -105,28 +106,9 @@ The preceding code:
105106

106107
When this app host is run, the life cycle hook is executed for each event. The following output is generated:
107108

108-
```Output
109-
info: LifecycleLogger[0]
110-
BeforeStartAsync
111-
info: Aspire.Hosting.DistributedApplication[0]
112-
Aspire version: 9.0.0
113-
info: Aspire.Hosting.DistributedApplication[0]
114-
Distributed application starting.
115-
info: Aspire.Hosting.DistributedApplication[0]
116-
Application host directory is: ..\AspireApp\AspireApp.AppHost
117-
info: LifecycleLogger[0]
118-
AfterEndpointsAllocatedAsync
119-
info: Aspire.Hosting.DistributedApplication[0]
120-
Now listening on: https://localhost:17043
121-
info: Aspire.Hosting.DistributedApplication[0]
122-
Login to the dashboard at https://localhost:17043/login?t=d80f598bc8a64c7ee97328a1cbd55d72
123-
info: LifecycleLogger[0]
124-
AfterResourcesCreatedAsync
125-
info: Aspire.Hosting.DistributedApplication[0]
126-
Distributed application started. Press Ctrl+C to shut down.
127-
```
128-
129-
The preferred way to hook into the app host life cycle is to use the eventing API. For more information, see [Eventing in .NET Aspire](#eventing-in-net-aspire).
109+
:::code language="Plaintext" source="../fundamentals/snippets/lifecycles/AspireApp/AspireApp.AppHost/Console.txt" highlight="2,10,16":::
110+
111+
The preferred way to hook into the app host life cycle is to use the eventing API. For more information, see [App host eventing](#app-host-eventing).
130112

131113
## See also
132114

docs/app-host/snippets/AspireApp/AspireApp.AppHost/AspireApp.AppHost.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
</ItemGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.2.1" />
20-
<PackageReference Include="Aspire.Hosting.Redis" Version="9.2.1" />
19+
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.3.0-preview.1.25262.2" />
20+
<PackageReference Include="Aspire.Hosting.Redis" Version="9.3.0-preview.1.25262.2" />
2121
</ItemGroup>
2222

2323
</Project>
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
info: Program[0]
22
1. BeforeStartEvent
33
info: Aspire.Hosting.DistributedApplication[0]
4-
Aspire version: 9.0.0
4+
Aspire version: 9.3.0-preview.1.25262.2+6d54dc081cd2e7ea435e33f7c0e62ff6946ae66d
55
info: Aspire.Hosting.DistributedApplication[0]
66
Distributed application starting.
77
info: Aspire.Hosting.DistributedApplication[0]
8-
Application host directory is: ..\AspireApp\AspireApp.AppHost
8+
Application host directory is: ../AspireApp/AspireApp.AppHost
99
info: Program[0]
1010
2. AfterEndpointsAllocatedEvent
11+
3. 'aspire-dashboard' ResourceEndpointsAllocatedEvent
12+
3. 'cache' ResourceEndpointsAllocatedEvent
13+
3. 'apiservice' ResourceEndpointsAllocatedEvent
14+
3. 'webfrontend' ResourceEndpointsAllocatedEvent
1115
info: Aspire.Hosting.DistributedApplication[0]
1216
Now listening on: https://localhost:17178
1317
info: Aspire.Hosting.DistributedApplication[0]
1418
Login to the dashboard at https://localhost:17178/login?t=<YOUR_TOKEN>
1519
info: Program[0]
16-
3. AfterResourcesCreatedEvent
20+
4. AfterResourcesCreatedEvent
1721
info: Aspire.Hosting.DistributedApplication[0]
18-
Distributed application started. Press Ctrl+C to shut down.
22+
Distributed application started. Press Ctrl+C to shut down.

docs/app-host/snippets/AspireApp/AspireApp.AppHost/Program.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@
1414
.WithReference(apiService)
1515
.WaitFor(apiService);
1616

17+
builder.Eventing.Subscribe<ResourceEndpointsAllocatedEvent>(
18+
(@event, cancellationToken) =>
19+
{
20+
// The event doesn't expose an IServiceProvider, just write to the console.
21+
Console.WriteLine($"""
22+
3. '{@event.Resource.Name}' ResourceEndpointsAllocatedEvent
23+
""");
24+
25+
return Task.CompletedTask;
26+
});
27+
1728
builder.Eventing.Subscribe<BeforeStartEvent>(
1829
static (@event, cancellationToken) =>
1930
{
@@ -39,7 +50,7 @@
3950
{
4051
var logger = @event.Services.GetRequiredService<ILogger<Program>>();
4152

42-
logger.LogInformation("3. AfterResourcesCreatedEvent");
53+
logger.LogInformation("4. AfterResourcesCreatedEvent");
4354

4455
return Task.CompletedTask;
4556
});

docs/app-host/snippets/AspireApp/AspireApp.ResourceAppHost/AspireApp.ResourceAppHost.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
</ItemGroup>
1717

1818
<ItemGroup>
19-
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.2.1" />
20-
<PackageReference Include="Aspire.Hosting.Redis" Version="9.2.1" />
19+
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.3.0-preview.1.25262.2" />
20+
<PackageReference Include="Aspire.Hosting.Redis" Version="9.3.0-preview.1.25262.2" />
2121
</ItemGroup>
2222

2323
</Project>
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
info: Aspire.Hosting.DistributedApplication[0]
2-
Aspire version: 9.0.0
2+
Aspire version: 9.3.0
33
info: Aspire.Hosting.DistributedApplication[0]
44
Distributed application starting.
55
info: Aspire.Hosting.DistributedApplication[0]
6-
Application host directory is: ..\AspireApp\AspireApp.AppHost
6+
Application host directory is: ../AspireApp/AspireApp.AppHost
77
info: Program[0]
8-
1. ConnectionStringAvailableEvent
8+
1. InitializeResourceEvent
99
info: Program[0]
10-
2. BeforeResourceStartedEvent
10+
2. ConnectionStringAvailableEvent
1111
info: Program[0]
12-
3. ResourceReadyEvent
12+
3. BeforeResourceStartedEvent
1313
info: Aspire.Hosting.DistributedApplication[0]
1414
Now listening on: https://localhost:17222
1515
info: Aspire.Hosting.DistributedApplication[0]
1616
Login to the dashboard at https://localhost:17222/login?t=<YOUR_TOKEN>
17+
info: Program[0]
18+
4. ResourceReadyEvent
1719
info: Aspire.Hosting.DistributedApplication[0]
1820
Distributed application started. Press Ctrl+C to shut down.

docs/app-host/snippets/AspireApp/AspireApp.ResourceAppHost/Program.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@
1111
{
1212
var logger = @event.Services.GetRequiredService<ILogger<Program>>();
1313

14-
logger.LogInformation("3. ResourceReadyEvent");
14+
logger.LogInformation("4. ResourceReadyEvent");
15+
16+
return Task.CompletedTask;
17+
});
18+
19+
builder.Eventing.Subscribe<InitializeResourceEvent>(cache.Resource,
20+
static (@event, cancellationToken) =>
21+
{
22+
var logger = @event.Services.GetRequiredService<ILogger<Program>>();
23+
24+
logger.LogInformation("1. InitializeResourceEvent");
1525

1626
return Task.CompletedTask;
1727
});
@@ -22,7 +32,7 @@
2232
{
2333
var logger = @event.Services.GetRequiredService<ILogger<Program>>();
2434

25-
logger.LogInformation("2. BeforeResourceStartedEvent");
35+
logger.LogInformation("3. BeforeResourceStartedEvent");
2636

2737
return Task.CompletedTask;
2838
});
@@ -33,7 +43,7 @@
3343
{
3444
var logger = @event.Services.GetRequiredService<ILogger<Program>>();
3545

36-
logger.LogInformation("1. ConnectionStringAvailableEvent");
46+
logger.LogInformation("2. ConnectionStringAvailableEvent");
3747

3848
return Task.CompletedTask;
3949
});
Loading

0 commit comments

Comments
 (0)