Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.NET Aspire 9.0 - GA Release content #1867

Merged
merged 127 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 125 commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
fa00483
Initial bits...WIP, early draft
IEvangelist Oct 17, 2024
a0b3560
Add draft SDK content
IEvangelist Oct 17, 2024
5b5bc86
A few more bits
IEvangelist Oct 17, 2024
4e52074
SDK
IEvangelist Oct 17, 2024
0bcaa9c
Tons of updates, additions, removals, and whatnot.
IEvangelist Oct 17, 2024
143f6d1
Sweeping updates
IEvangelist Oct 17, 2024
9b707d5
Fix links
IEvangelist Oct 21, 2024
77490b1
Initial parts of eventing
IEvangelist Oct 23, 2024
4b9c5da
Fix a few build issues
IEvangelist Oct 23, 2024
9894b7f
More issues
IEvangelist Oct 23, 2024
064a1e3
Add eventing to TOC
IEvangelist Oct 23, 2024
063223f
Added txt for console output
IEvangelist Oct 24, 2024
4a64b24
Eventing API content, getting closer
IEvangelist Oct 24, 2024
391c20b
A bit more clean up
IEvangelist Oct 24, 2024
532701a
Fix hosting meilisearch
IEvangelist Oct 24, 2024
731bbc7
More SDK updates
IEvangelist Oct 24, 2024
f9dd2d6
More SDK clarification
IEvangelist Oct 24, 2024
b214084
index tweaks
IEvangelist Oct 24, 2024
771d769
Try using uppercase slug
IEvangelist Oct 24, 2024
c00cfa1
Fix publish API
IEvangelist Oct 24, 2024
f36d9bd
Add zones to upgrade
IEvangelist Oct 24, 2024
98912c3
Some breaking changes
IEvangelist Oct 24, 2024
eecaf72
More links to API change
IEvangelist Oct 24, 2024
228976f
Add API removal text
IEvangelist Oct 24, 2024
fe16ee7
TOC updates
IEvangelist Oct 24, 2024
ed6f256
More breaking changes and fix podman
IEvangelist Oct 25, 2024
0b74e12
Trying a few things with the TOC
IEvangelist Oct 25, 2024
59d1080
Generate the breaking-changes
IEvangelist Oct 28, 2024
5739670
Clean up
IEvangelist Oct 28, 2024
8e8bdb4
Add AI metadata
IEvangelist Oct 28, 2024
d73e874
Fix TOC
IEvangelist Oct 28, 2024
40f95ec
Add a few more bits for the upgrade content
IEvangelist Oct 28, 2024
301084c
Fix lightbox attribute
IEvangelist Oct 28, 2024
e3a22e3
Missing attribute
IEvangelist Oct 28, 2024
8e25e09
New line
IEvangelist Oct 28, 2024
09928e7
Edit pass
IEvangelist Oct 29, 2024
7b57ad5
Upgrade quickstart to .NET Aspire 9.0, and update some dashboard images
IEvangelist Oct 29, 2024
5dfd2fd
Update dashboard bits, images, and add actions section
IEvangelist Oct 29, 2024
4e3bb29
Fix link, no troubleshooting
IEvangelist Oct 29, 2024
09274a4
More resource action updates
IEvangelist Oct 29, 2024
bbc08b7
Remove edges
IEvangelist Oct 29, 2024
deca6eb
Fixes #1823
IEvangelist Oct 29, 2024
db325da
Add details for app host lifecylce
IEvangelist Oct 29, 2024
ce5c3a3
Demote alert
IEvangelist Oct 29, 2024
dd2448e
Edit pass
IEvangelist Oct 29, 2024
769cb8d
Edit pass and additions.
IEvangelist Oct 30, 2024
f462e04
Edit pass and highlighting
IEvangelist Oct 30, 2024
a891785
Let's see how far we've come
IEvangelist Oct 30, 2024
f57e379
Lots of updates
IEvangelist Oct 30, 2024
b44c2f8
Move a few things
IEvangelist Oct 30, 2024
03a7e90
Added error
IEvangelist Oct 30, 2024
cab8129
Remove discards.
IEvangelist Oct 30, 2024
bb078f1
Apply suggestions from code review
IEvangelist Oct 31, 2024
588c6b2
Additional feedback
IEvangelist Oct 31, 2024
8afb854
Fix learn site issue reporting.
IEvangelist Oct 31, 2024
5fa5c54
Fix link...
IEvangelist Oct 31, 2024
393acf1
Fixes #2003
IEvangelist Oct 31, 2024
804ff3b
Edit pass on explore dashboard
IEvangelist Oct 31, 2024
d2e976c
More clean up
IEvangelist Oct 31, 2024
1f1e04e
Add details for WaitFor/Completion APIs.
IEvangelist Oct 31, 2024
1bdf2e2
Fixes from build report.
IEvangelist Oct 31, 2024
1073ca3
Remove snippets for Functions
IEvangelist Oct 31, 2024
c4f6a0a
Update overview.md
mitchdenny Nov 1, 2024
8fe602f
Update dotnet-aspire-sdk.md
mitchdenny Nov 1, 2024
6d40011
Update eventing.md
mitchdenny Nov 1, 2024
8d4796a
Update eventing.md
mitchdenny Nov 1, 2024
0fbd03a
Update docs/app-host/eventing.md
IEvangelist Nov 1, 2024
5088eae
Add Ollama integration updates.
IEvangelist Nov 4, 2024
a77a788
Fix headings and sections
IEvangelist Nov 4, 2024
ce1e4d2
Lots of updates and fixes
IEvangelist Nov 4, 2024
a9acaca
Upgrade a few more bits, quickstart and setup/tooling
IEvangelist Nov 4, 2024
5e33099
Fix build
IEvangelist Nov 4, 2024
ce77e3a
Additions, version fixes, etc.
IEvangelist Nov 4, 2024
a4adf43
Clean up some of the image/diagrams
IEvangelist Nov 4, 2024
bdbe40b
Fixing updated APIs
IEvangelist Nov 4, 2024
68a8d22
Added a few bits to address #1704
IEvangelist Nov 4, 2024
3c81ef3
Addresses #2004
IEvangelist Nov 4, 2024
7924855
Apply suggestions from code review
IEvangelist Nov 5, 2024
b6fb7bf
Fix broken link
IEvangelist Nov 5, 2024
0538a06
Rewrite the toolkit overview. Update some images
IEvangelist Nov 5, 2024
37bf565
Remove images
IEvangelist Nov 5, 2024
533d3c7
Fix link and minor edits
IEvangelist Nov 5, 2024
5092c0f
Move Azure Cache for Redis to the bottom
IEvangelist Nov 5, 2024
c44219b
Fix MD lint
IEvangelist Nov 5, 2024
e0c0651
Edit pass on the Orleans content. Also, fixes #1818
IEvangelist Nov 5, 2024
19fefa5
Move Azure PostgreSQL bits to the bottom of the page
IEvangelist Nov 5, 2024
839f40e
Try fixing the zones
IEvangelist Nov 5, 2024
71523f8
Fix MD lint error
IEvangelist Nov 5, 2024
d88ee90
Fix more broken zones
IEvangelist Nov 5, 2024
d8596cf
Add see also section
IEvangelist Nov 5, 2024
720d8fb
Setup and tooling TOC updates
IEvangelist Nov 5, 2024
143ba50
Re-order TOC
IEvangelist Nov 5, 2024
fc4409a
Update docs/app-host/eventing.md
IEvangelist Nov 6, 2024
dd19223
Updates for the tutorial on adding Aspire to existing app
IEvangelist Nov 6, 2024
f3c6697
Repurpose RC1, redirects, edit pass, links, etc.
IEvangelist Nov 6, 2024
0663562
Fix the TOC
IEvangelist Nov 6, 2024
9fd867d
Edit pass and cleanup of explore and what's new in .NET Aspire 9
IEvangelist Nov 6, 2024
e11660d
Added custom command article
IEvangelist Nov 7, 2024
e81ac0c
Add to TOC
IEvangelist Nov 7, 2024
c134772
Fix #2016, update to latest templates
IEvangelist Nov 7, 2024
48610f8
Fix #2022
IEvangelist Nov 7, 2024
323c215
A bit of container love
IEvangelist Nov 8, 2024
fb8b2e6
A bit more clean up
IEvangelist Nov 8, 2024
202203b
Be more consistent with references to NuGet packages
IEvangelist Nov 8, 2024
4840b7d
Fix #2027
IEvangelist Nov 8, 2024
d5c9704
Fix regex replace. :|
IEvangelist Nov 8, 2024
81027b4
Fix #2026
IEvangelist Nov 8, 2024
0a2510b
Apply suggestions from code review
IEvangelist Nov 8, 2024
0542c51
A few bits of peer feedback
IEvangelist Nov 8, 2024
38b7424
Some fixes related to #2024
IEvangelist Nov 8, 2024
2f6cdf4
Fix #2017
IEvangelist Nov 8, 2024
13bae6d
Apply suggestions from code review
IEvangelist Nov 9, 2024
20e1f57
Fix suggestion
IEvangelist Nov 9, 2024
5c24630
Update docs/fundamentals/aspire-sdk-templates.md
IEvangelist Nov 9, 2024
a728261
A few peer bits of feedback
IEvangelist Nov 9, 2024
396c1a9
Fix (update) create new project images
IEvangelist Nov 11, 2024
4622d3f
Fix include and delete legacy media
IEvangelist Nov 11, 2024
a4a4e20
Isolate to selection, readd media
IEvangelist Nov 11, 2024
34a0709
Fix #1993
IEvangelist Nov 11, 2024
a7f45a0
A few more bits of cleanup
IEvangelist Nov 11, 2024
eea1284
Remove .NET Aspire SDK as a prereq
IEvangelist Nov 11, 2024
aaf77e5
A few bits of additional context.
IEvangelist Nov 12, 2024
f4dec25
More links
IEvangelist Nov 12, 2024
b6c0c50
Tidy
IEvangelist Nov 12, 2024
d462fa0
Consistent sentence
IEvangelist Nov 12, 2024
de6effb
Bump DOTNET_VERSION
IEvangelist Nov 12, 2024
4a137b8
Remove install of workload
IEvangelist Nov 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 4 additions & 0 deletions .openpublishing.redirection.json
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,10 @@
{
"source_path_from_root": "/docs/fundamentals/testing.md",
"redirect_url": "/dotnet/aspire/testing/write-your-first-test"
},
{
"source_path_from_root": "/docs/whats-new/dotnet-aspire-9-release-candidate-1.md",
"redirect_url": "/dotnet/aspire/whats-new/dotnet-aspire-9"
}
]
}
4 changes: 3 additions & 1 deletion docfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"open_source_feedback_issueTitle": "",
"open_source_feedback_productLogoLightUrl": "https://learn.microsoft.com/media/logos/logo_net.svg",
"open_source_feedback_productLogoDarkUrl": "https://learn.microsoft.com/media/logos/logo_net.svg",
"open_source_feedback_issueUrl": "https://github.com/dotnet/docs-aspire/issues/new?template=customer-feedback.yml",
"open_source_feedback_issueUrl": "https://github.com/dotnet/docs-aspire/issues/new?template=z-customer-feedback.yml",
"open_source_feedback_productName": ".NET Aspire",
"open_source_feedback_productDescription": "The .NET Aspire documentation is open source and we love community feedback. Please provide feedback by posting an issue on GitHub, or product feedback here:",
"social_image_url": "/dotnet/media/dotnet-aspire-logo.png",
Expand Down Expand Up @@ -154,6 +154,7 @@
"cookie",
"Cosmos DB",
"Dapr",
"Deno",
"Docker",
"Dockerfile",
"EF Core",
Expand Down Expand Up @@ -181,6 +182,7 @@
"Postgres",
"PostgreSQL",
"Privacy",
"Python",
"RabbitMQ",
"React",
"Redis",
Expand Down
87 changes: 87 additions & 0 deletions docs/app-host/eventing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
title: Eventing in .NET Aspire
description: Learn how to use the .NET eventing features with .NET Aspire.
ms.date: 10/30/2024
---

# Eventing in .NET Aspire

In .NET Aspire, eventing allows you to publish and subscribe to events during various [app host life cycles](xref:dotnet/aspire/app-host#app-host-life-cycles). Eventing is more flexible than life cycle events. Both let you run arbitrary code during event callbacks, but eventing offers finer control of event timing, publishing, and provides supports for custom events.

The eventing mechanisms in .NET Aspire are part of the [📦 Aspire.Hosting](https://www.nuget.org/packages/Aspire.Hosting) NuGet package. This package provides a set of interfaces and classes in the <xref:Aspire.Hosting.Eventing> namespace that you use to publish and subscribe to events in your .NET Aspire app host project. Eventing is scoped to the app host itself and the resources within.

In this article, you learn how to use the eventing features in .NET Aspire.

## App host eventing

The following events are available in the app host and occur in the following order:

1. <xref:Aspire.Hosting.ApplicationModel.BeforeStartEvent>: This event is raised before the app host starts.
1. <xref:Aspire.Hosting.ApplicationModel.AfterEndpointsAllocatedEvent>: This event is raised after the app host allocated endpoints.
1. <xref:Aspire.Hosting.ApplicationModel.AfterResourcesCreatedEvent>: This event is raised after the app host created resources.

All of the preceding events are analogous to the [app host life cycles](xref:dotnet/aspire/app-host#app-host-life-cycles). That is, an implementation of the <xref:Aspire.Hosting.Lifecycle.IDistributedApplicationLifecycleHook> could handle these events just the same. With the eventing API, however, you can run arbitrary code when these events are raised and event define custom events—any event that implements the <xref:Aspire.Hosting.Eventing.IDistributedApplicationEvent> interface.
IEvangelist marked this conversation as resolved.
Show resolved Hide resolved

### Subscribe to app host events

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:

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

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.
IEvangelist marked this conversation as resolved.
Show resolved Hide resolved

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:

:::code language="Plaintext" source="snippets/AspireApp/AspireApp.AppHost/Console.txt" highlight="2,10,16":::

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`.

## Resource eventing

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:

1. `ConnectionStringAvailableEvent`: Raised when a connection string becomes available for a resource.
1. `BeforeResourceStartedEvent`: Raised before the orchestrator starts a new resource.
1. `ResourceReadyEvent`: Raised when a resource initially transitions to a ready state.

### Subscribe to resource events

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:

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

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.

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:

:::code language="Plaintext" source="snippets/AspireApp/AspireApp.ResourceAppHost/Console.txt" highlight="8,10,12":::

> [!NOTE]
> 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).

## Publish events

When subscribing to any of the built-in events, you don't need to publish the event yourself as the app host orchestrator manages to publish built-in events on your behalf. However, you can publish custom events with the eventing API. To publish an event, you have to first define an event as an implementation of either the <xref:Aspire.Hosting.Eventing.IDistributedApplicationEvent> or <xref:Aspire.Hosting.Eventing.IDistributedApplicationResourceEvent> interface. You need to determine which interface to implement based on whether the event is a global app host event or a resource-specific event.

Then, you can subscribe and publish the event by calling the either of the following APIs:

- <xref:Aspire.Hosting.Eventing.IDistributedApplicationEventing.PublishAsync``1(``0,System.Threading.CancellationToken)>: Publishes an event to all subscribes of the specific event type.
- `PublishAsync<T>(T, EventDispatchBehavior, CancellationToken)`: Publishes an event to all subscribes of the specific event type with a specified dispatch behavior.

### Provide an `EventDispatchBehavior`

When events are dispatched, you can control how the events are dispatched to subscribers. The event dispatch behavior is specified with the `EventDispatchBehavior` enum. The following behaviors are available:

<!--
- <xref:Aspire.Hosting.Eventing.EventDispatchBehavior.BlockingSequential>: Fires events sequentially and blocks until they're all processed.
- <xref:Aspire.Hosting.Eventing.EventDispatchBehavior.BlockingConcurrent>: Fires events concurrently and blocks until they are all processed.
- <xref:Aspire.Hosting.Eventing.EventDispatchBehavior.NonBlockingSequential>: Fires events sequentially but doesn't block.
- <xref:Aspire.Hosting.Eventing.EventDispatchBehavior.NonBlockingConcurrent>: Fires events concurrently but doesn't block.
-->

- `EventDispatchBehavior.BlockingSequential`: Fires events sequentially and blocks until they're all processed.
- `EventDispatchBehavior.BlockingConcurrent`: Fires events concurrently and blocks until they're all processed.
- `EventDispatchBehavior.NonBlockingSequential`: Fires events sequentially but doesn't block.
- `EventDispatchBehavior.NonBlockingConcurrent`: Fires events concurrently but doesn't block.

The default behavior is `EventDispatchBehavior.BlockingSequential`. To override this behavior, when calling a publishing API such as <xref:Aspire.Hosting.Eventing.IDistributedApplicationEventing.PublishAsync*>, provide the desired behavior as an argument.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AspireApp.ServiceDefaults\AspireApp.ServiceDefaults.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var builder = WebApplication.CreateBuilder(args);

// Add service defaults & Aspire client integrations.
builder.AddServiceDefaults();

// Add services to the container.
builder.Services.AddProblemDetails();

var app = builder.Build();

// Configure the HTTP request pipeline.
app.UseExceptionHandler();

var summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

app.MapGet("/weatherforecast", () =>
{
var forecast = Enumerable.Range(1, 5).Select(index =>
new WeatherForecast
(
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
Random.Shared.Next(-20, 55),
summaries[Random.Shared.Next(summaries.Length)]
))
.ToArray();
return forecast;
});

app.MapDefaultEndpoints();

app.Run();

record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "http://localhost:5562",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:7482;http://localhost:5562",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>7b352f08-305b-4032-9a21-90deb02efc04</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AspireApp.ApiService\AspireApp.ApiService.csproj" />
<ProjectReference Include="..\AspireApp.Web\AspireApp.Web.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0" />
<PackageReference Include="Aspire.Hosting.Redis" Version="9.0.0" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions docs/app-host/snippets/AspireApp/AspireApp.AppHost/Console.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
info: Program[0]
1. BeforeStartEvent
info: Aspire.Hosting.DistributedApplication[0]
Aspire version: 9.0.0
info: Aspire.Hosting.DistributedApplication[0]
Distributed application starting.
info: Aspire.Hosting.DistributedApplication[0]
Application host directory is: ..\AspireApp\AspireApp.AppHost
info: Program[0]
2. AfterEndpointsAllocatedEvent
info: Aspire.Hosting.DistributedApplication[0]
Now listening on: https://localhost:17178
info: Aspire.Hosting.DistributedApplication[0]
Login to the dashboard at https://localhost:17178/login?t=<YOUR_TOKEN>
info: Program[0]
3. AfterResourcesCreatedEvent
info: Aspire.Hosting.DistributedApplication[0]
Distributed application started. Press Ctrl+C to shut down.
47 changes: 47 additions & 0 deletions docs/app-host/snippets/AspireApp/AspireApp.AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddRedis("cache");

var apiService = builder.AddProject<Projects.AspireApp_ApiService>("apiservice");

builder.AddProject<Projects.AspireApp_Web>("webfrontend")
.WithExternalHttpEndpoints()
.WithReference(cache)
.WaitFor(cache)
.WithReference(apiService)
.WaitFor(apiService);

builder.Eventing.Subscribe<BeforeStartEvent>(
static (@event, cancellationToken) =>
{
var logger = @event.Services.GetRequiredService<ILogger<Program>>();

logger.LogInformation("1. BeforeStartEvent");

return Task.CompletedTask;
});

builder.Eventing.Subscribe<AfterEndpointsAllocatedEvent>(
static (@event, cancellationToken) =>
{
var logger = @event.Services.GetRequiredService<ILogger<Program>>();

logger.LogInformation("2. AfterEndpointsAllocatedEvent");

return Task.CompletedTask;
});

builder.Eventing.Subscribe<AfterResourcesCreatedEvent>(
static (@event, cancellationToken) =>
{
var logger = @event.Services.GetRequiredService<ILogger<Program>>();

logger.LogInformation("3. AfterResourcesCreatedEvent");

return Task.CompletedTask;
});

builder.Build().Run();
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17178;http://localhost:15142",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21137",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22259"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15142",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19091",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20229"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning",
"Aspire.Hosting.Dcp": "Warning"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" />

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>7b352f08-305b-4032-9a21-90deb02efc04</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\AspireApp.ApiService\AspireApp.ApiService.csproj" />
<ProjectReference Include="..\AspireApp.Web\AspireApp.Web.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0" />
<PackageReference Include="Aspire.Hosting.Redis" Version="9.0.0" />
</ItemGroup>

</Project>
Loading
Loading