Skip to content

Commit 5a4f555

Browse files
authored
feat: Implement .NET Aspire orchestration in Chapter 4 (#234)
1 parent a5404e9 commit 5a4f555

8 files changed

Lines changed: 123 additions & 1 deletion

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<Project>
2+
3+
</Project>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project>
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4+
</PropertyGroup>
5+
<ItemGroup Label="Production">
6+
<PackageVersion Include="Aspire.Hosting.AppHost" Version="13.0.0" />
7+
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="13.0.0" />
8+
<PackageVersion Include="Aspire.Hosting.RabbitMQ" Version="13.0.0" />
9+
</ItemGroup>
10+
</Project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<IsAspireHost>true</IsAspireHost>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Aspire.Hosting.AppHost" />
10+
<PackageReference Include="Aspire.Hosting.PostgreSQL" />
11+
<PackageReference Include="Aspire.Hosting.RabbitMQ" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\Fitnet.Contracts\Src\Fitnet.Contracts\Fitnet.Contracts.csproj" />
16+
<ProjectReference Include="..\Fitnet\Src\Fitnet\Fitnet.csproj" />
17+
</ItemGroup>
18+
19+
</Project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using Projects;
2+
3+
var builder = DistributedApplication.CreateBuilder(args);
4+
5+
var postgres = builder.AddPostgres("postgres")
6+
.WithImage("postgres", "14.3")
7+
.WithPgAdmin();
8+
9+
var fitnetDatabase = postgres.AddDatabase("fitnetsdb", "fitnet");
10+
11+
var rabbitmq = builder.AddRabbitMQ("rabbitmq")
12+
.WithManagementPlugin();
13+
14+
builder.AddProject<Fitnet>("fitnet-modular-monolith")
15+
.WithEnvironment("ASPNETCORE_ENVIRONMENT", "Development")
16+
.WithReference(fitnetDatabase, "Database__ConnectionString")
17+
.WithReference(rabbitmq, "EventBus__ConnectionString")
18+
.WaitFor(postgres)
19+
.WaitFor(rabbitmq);
20+
21+
builder.AddProject<Fitnet_Contracts>("fitnet-contracts-microservice")
22+
.WithEnvironment("ASPNETCORE_ENVIRONMENT", "Development")
23+
.WithReference(fitnetDatabase, "Database__ConnectionString")
24+
.WithReference(rabbitmq, "EventBus__ConnectionString")
25+
.WaitFor(postgres)
26+
.WaitFor(rabbitmq);
27+
28+
await builder.Build().RunAsync();
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning",
6+
"Aspire.Hosting.DistributedApplication": "Information"
7+
}
8+
}
9+
}

Chapter-4-applying-tactical-domain-driven-design/Fitnet.Contracts/Src/Fitnet.Contracts.Infrastructure/EventBus/EventBusModule.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,23 @@ internal static IServiceCollection AddEventBus(this IServiceCollection services,
2323
{
2424
return;
2525
}
26-
26+
var uri = options.Value?.Uri;
27+
var username = options.Value?.Username;
28+
var password = options.Value?.Password;
29+
if (!string.IsNullOrEmpty(uri))
30+
{
31+
factoryConfigurator.Host(uri, h =>
32+
{
33+
if (!string.IsNullOrEmpty(username))
34+
{
35+
h.Username(username);
36+
}
37+
if (!string.IsNullOrEmpty(password))
38+
{
39+
h.Password(password);
40+
}
41+
});
42+
}
2743
factoryConfigurator.ConfigureEndpoints(context);
2844
});
2945
});

Chapter-4-applying-tactical-domain-driven-design/Fitnet/Src/Passes/Fitnet.Passes.Api/Common/EventBus/EventBusModule.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ internal static IServiceCollection AddEventBus(this IServiceCollection services,
2626
{
2727
return;
2828
}
29+
var uri = options.Value?.Uri;
30+
var username = options.Value?.Username;
31+
var password = options.Value?.Password;
32+
if (!string.IsNullOrEmpty(uri))
33+
{
34+
factoryConfigurator.Host(uri, h =>
35+
{
36+
if (!string.IsNullOrEmpty(username))
37+
{
38+
h.Username(username);
39+
}
40+
if (!string.IsNullOrEmpty(password))
41+
{
42+
h.Password(password);
43+
}
44+
});
45+
}
2946
factoryConfigurator.ConfigureEndpoints(context);
3047
});
3148
configurator.ConfigureOutbox();

Chapter-4-applying-tactical-domain-driven-design/README.adoc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,26 @@ The `Contracts` microservice runs on port `:8081`. Please navigate to http://loc
374374

375375
That's it! You should now be able to run the application using either one of the above. :thumbsup:
376376

377+
=== Run with .NET Aspire
378+
379+
The Fitnet application uses .NET Aspire for local development.
380+
381+
To run the application locally using Aspire, follow these steps:
382+
383+
1. **Ensure Docker is running** on your machine.
384+
2. **Navigate to the AppHost directory:**
385+
[source,shell]
386+
----
387+
cd Fitnet.AppHost
388+
----
389+
3. **Run the AppHost project:**
390+
[source,shell]
391+
----
392+
dotnet run
393+
----
394+
395+
The Aspire Dashboard will open automatically, showing all services, resources, and logs.
396+
377397
=== Building and debugging code in Rider IDE
378398

379399
Before you build or debug code in `Rider` or `Visual Studio` IDE, you first have to provide your username and previously generated PAT for artifactory to download packages for `Common` which is a part of this repository. When you load the solution, your IDE should request the credentials:

0 commit comments

Comments
 (0)