Skip to content

Commit 33d6ce8

Browse files
authored
feat: Implement separate .NET Aspire orchestration for Fitnet and Fitnet.Contracts in Chapter 3 (#227)
1 parent 3a211e6 commit 33d6ce8

File tree

14 files changed

+172
-49
lines changed

14 files changed

+172
-49
lines changed

Chapter-3-microservice-extraction/Fitnet.Contracts/Src/Directory.Packages.props

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
</PropertyGroup>
55
<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" />
69
<PackageVersion Include="EvolutionaryArchitecture.Fitnet.Common.Api" Version="3.2.5" />
710
<PackageVersion Include="EvolutionaryArchitecture.Fitnet.Common.Core" Version="3.2.5" />
811
<PackageVersion Include="EvolutionaryArchitecture.Fitnet.Common.Infrastructure" Version="3.2.5" />
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Sdk Name="Aspire.AppHost.Sdk" Version="13.0.0" />
3+
4+
<PropertyGroup>
5+
<OutputType>Exe</OutputType>
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\Fitnet.Contracts.csproj" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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_Contracts>("fitnet-contracts-microservice")
15+
.WithEnvironment("ASPNETCORE_ENVIRONMENT", "Development")
16+
.WithReference(fitnetDatabase, "Database__ConnectionString")
17+
.WithReference(rabbitmq, "EventBus__ConnectionString")
18+
.WaitFor(postgres)
19+
.WaitFor(rabbitmq);
20+
21+
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-3-microservice-extraction/Fitnet.Contracts/Src/Fitnet.Contracts.Infrastructure/EventBus/EventBusModule.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,25 @@ internal static IServiceCollection AddEventBus(this IServiceCollection services,
2424
return;
2525
}
2626

27+
var uri = options.Value!.Uri;
28+
var username = options.Value!.Username;
29+
var password = options.Value!.Password;
30+
31+
if (!string.IsNullOrEmpty(uri))
32+
{
33+
factoryConfigurator.Host(uri, h =>
34+
{
35+
if (!string.IsNullOrEmpty(username))
36+
{
37+
h.Username(username);
38+
}
39+
if (!string.IsNullOrEmpty(password))
40+
{
41+
h.Password(password);
42+
}
43+
});
44+
}
45+
2746
factoryConfigurator.ConfigureEndpoints(context);
2847
});
2948
});

Chapter-3-microservice-extraction/Fitnet.Contracts/Src/Fitnet.Contracts.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@
1010
<Project Path="Fitnet.Contracts.Infrastructure\Fitnet.Contracts.Infrastructure.csproj" Type="Classic C#" />
1111
<Project Path="Fitnet.Contracts.IntegrationEvents\Fitnet.Contracts.IntegrationEvents.csproj" Type="Classic C#" />
1212
<Project Path="Fitnet.Contracts\Fitnet.Contracts.csproj" Type="Classic C#" />
13+
<Project Path="Fitnet.Contracts.AppHost\Fitnet.Contracts.AppHost.csproj" Type="Classic C#" />
1314
</Solution>

Chapter-3-microservice-extraction/Fitnet/Src/Directory.Packages.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
44
</PropertyGroup>
55
<ItemGroup Label="Production">
6+
<PackageVersion Include="Aspire.Hosting.AppHost" Version="13.0.0" />
7+
<PackageVersion Include="Aspire.Hosting.PostgreSQL" Version="13.0.0" />
68
<PackageVersion Include="Dapper" Version="2.1.66" />
79
<PackageVersion Include="EvolutionaryArchitecture.Fitnet.Common.Api" Version="3.2.5" />
810
<PackageVersion Include="EvolutionaryArchitecture.Fitnet.Common.Core" Version="3.2.5" />
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Sdk Name="Aspire.AppHost.Sdk" Version="13.0.0" />
3+
4+
<PropertyGroup>
5+
<OutputType>Exe</OutputType>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Aspire.Hosting.AppHost" />
10+
<PackageReference Include="Aspire.Hosting.PostgreSQL" />
11+
</ItemGroup>
12+
13+
<ItemGroup>
14+
<ProjectReference Include="..\Fitnet\Fitnet.csproj" />
15+
</ItemGroup>
16+
17+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
builder.AddProject<Fitnet>("fitnet-modular-monolith")
12+
.WithEnvironment("ASPNETCORE_ENVIRONMENT", "Development")
13+
.WithReference(fitnetDatabase, "Database__ConnectionString")
14+
.WaitFor(postgres);
15+
16+
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+
}

0 commit comments

Comments
 (0)