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

✨ 1 auto register modules and endpoints #21

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
6408c35
18 migrate from ca to vsa (#19)
danielmackay Jun 3, 2024
5344f0f
Started on module discovery
danielmackay Jun 5, 2024
aa00035
♻️ Tidied up modules so that only module registration code is public …
danielmackay Jun 5, 2024
8347137
♻️ Added customer module
danielmackay Jul 31, 2024
2435c96
♻️ Make Money more resilient
danielmackay Jul 31, 2024
1f75988
🧪 Added unit tests for LineItem.cs
danielmackay Jul 31, 2024
cdff596
✨ Added Customer and Catelog modules
danielmackay Aug 3, 2024
d24bdfc
♻️ Switched from Ardalis.GuardClauses to ErrorOr and Throw.
danielmackay Aug 3, 2024
814c404
Added storage to Warehouse domain model
danielmackay Aug 4, 2024
80a8acd
🎨 consolidate csproj settings by using Directory.Build.props
danielmackay Aug 5, 2024
7d1c5c7
Bump static code analysis to minimum
danielmackay Aug 11, 2024
45b1e40
♻️ Tidy up namespaces
danielmackay Aug 11, 2024
db391e1
✨ Added Catalog Product
danielmackay Aug 11, 2024
8c1c49c
✨ Added Payment to Order
danielmackay Aug 11, 2024
0b7c955
Added Warehouse BackOrder. Also introduced Ardalis.SmartEnum
danielmackay Aug 11, 2024
a1a6115
📝 Added Event Storming and Bounded Contexts
danielmackay Aug 11, 2024
c566b7f
✨ 26 catalog create invariants (#42)
danielmackay Aug 18, 2024
9878a20
✨ Added CartItem logic and tests
danielmackay Aug 19, 2024
baef97d
Add readonly property and unit tests to Cart class
danielmackay Aug 19, 2024
85999b6
✨ Add Payment and PaymentType entities; restructure Order module
danielmackay Aug 21, 2024
46337fb
🧪 Add comprehensive unit tests for Orders module
danielmackay Aug 21, 2024
7ffcef7
♻️ Enhance validation for `Address` and `Customer` classes
danielmackay Aug 21, 2024
ce14a6c
🧪 Add unit tests for Customer and Address classes
danielmackay Aug 21, 2024
699f58a
🧪 Consolidate AisleTests into ModelTests file
danielmackay Aug 22, 2024
6058c79
🌱 Up script and test database seed data (#43)
danielmackay Aug 25, 2024
2eaaa46
✨ Add integration test setup for Aisle creation
danielmackay Aug 25, 2024
f46321a
✨ We now set IAuditable properties when persisting entities.
danielmackay Aug 25, 2024
53ea3d8
✨ Integrate ErrorOr package and enhance validation handling
danielmackay Aug 25, 2024
cfe2778
✨ Added Create Product Command
danielmackay Aug 25, 2024
67dd3c9
🧪 Add product tests
danielmackay Aug 25, 2024
286393d
✨ Add ProductErrors class and product integration tests
danielmackay Aug 25, 2024
d833f1f
🐛 Fixed swagger and connection string errors
danielmackay Aug 25, 2024
a7b2dc6
♻️ Rename UseCases and Enhance Swagger Configuration
danielmackay Aug 26, 2024
d4b8940
✨ Add storage allocation feature
danielmackay Aug 26, 2024
f9ff722
🧪 Consolidate StorageAllocationServiceTests files
danielmackay Aug 26, 2024
6f23e7b
♻️ Refactor namespace and update imports
danielmackay Aug 26, 2024
5171f51
✨ add item location endpoint
danielmackay Aug 26, 2024
fb1d4c6
♻️ Refactor test file structure for clearer module separation
danielmackay Aug 26, 2024
f00a33f
🧪 Add GetItemLocationQuery endpoint and integration test
danielmackay Aug 26, 2024
0306527
✨ Introduce event dispatching and IDomainEvent interface
danielmackay Aug 27, 2024
0e1c729
✨ Implement product storage integration events
danielmackay Aug 27, 2024
bf7c161
✨ Add Catalog module and update domain events usage
danielmackay Aug 27, 2024
77598b2
✨ Add new unit tests for Aisle class in warehouse module
danielmackay Aug 27, 2024
91519de
✨ Restructure Catalog and Warehouse, enhance persistence
danielmackay Aug 28, 2024
b31a9c3
🌱 Add categories seeding to CatalogDbContext
danielmackay Aug 28, 2024
102bb82
✨ Add database saving logic for Product in event handler
danielmackay Aug 29, 2024
8fa4917
🧪 Add WebApi.Tests project to the solution
danielmackay Aug 29, 2024
5ff7223
🧪 Refactor test infrastructure for modularity
danielmackay Aug 29, 2024
d2bf85c
🧪 Add test report to GitHub workflow (#47)
danielmackay Aug 29, 2024
6d78518
🐛 Fix broken tests
danielmackay Aug 29, 2024
b2f680f
✨ Add create category command and integration tests
danielmackay Aug 29, 2024
8ee7978
✨ Add commands to manage product categories in the catalog
danielmackay Aug 29, 2024
39d0923
🧪 Implement product category management with integration tests
danielmackay Aug 29, 2024
869eded
✨ Add GetProductQuery use case to CatalogModule
danielmackay Sep 2, 2024
3c8b3b0
🧪 Improve GetProductQuery response handling and add tests
danielmackay Sep 2, 2024
5d2f882
✨ Add UpdateProductPriceCommand functionality
danielmackay Sep 2, 2024
b604daf
✨ Add update product price endpoint and test coverage
danielmackay Sep 2, 2024
abb6423
📦 Update package dependencies across several projects
danielmackay Sep 2, 2024
180117d
✨ Add search functionality to products
danielmackay Sep 11, 2024
33e6ee2
✨ Add global error handler and update test dependencies
danielmackay Sep 11, 2024
07d495c
📦 Upgraded to .NET 9 RC
danielmackay Sep 13, 2024
66c01c6
✨ Upgrade .NET version in GitHub Actions workflow
danielmackay Sep 13, 2024
31361fd
🚨 fixed all warnings
danielmackay Sep 13, 2024
0b3a27d
✨ Upgrade setup-dotnet action to version 4
danielmackay Sep 13, 2024
69d7039
🧪 fix test containers
danielmackay Sep 19, 2024
35fbe7b
🧪 Another crack at fixing the tests
danielmackay Sep 20, 2024
70643ba
Temporarily remove tests
danielmackay Sep 20, 2024
382af55
🧪 added retry to test container creation
danielmackay Sep 25, 2024
4108a17
Switched to using Guid.CreateVersion7()
danielmackay Sep 25, 2024
bd7c097
♻️ Improved usage of StrongTyped IDs
danielmackay Sep 25, 2024
f335423
♻️ Improved Test Container retry by introducing Polly
danielmackay Sep 25, 2024
38d44be
✨ Add EntityFramework.Exceptions to produce easy to read errors
danielmackay Sep 25, 2024
27830e9
🧪 Refactor tests and add migrations (#58)
danielmackay Sep 26, 2024
922bf05
✨ Added register customer command
danielmackay Sep 28, 2024
fff621a
🧪 Added register customer tests and custom HTTP assertions.
danielmackay Oct 2, 2024
4a734ad
✨ Add item to cart (#60)
danielmackay Oct 7, 2024
2ff5e8d
✨ 16 Replace Docker Compose with Aspire (#61)
danielmackay Oct 9, 2024
ef74e3e
📦 Upgrade packages to .NET 9 RC 2
danielmackay Oct 10, 2024
5c6073c
📦 Upgrade other nuget packages
danielmackay Oct 10, 2024
52a04e2
♻️ Refactor to use SLNX solution file
danielmackay Oct 10, 2024
931bb63
🐛 Fix transaction migration issue
danielmackay Oct 10, 2024
90fd720
🧱 Run all DBs in a single Server in AppHost
danielmackay Oct 10, 2024
e88cd44
♻️ Small tidy up
danielmackay Oct 10, 2024
c0a832f
Merge branch 'main' into 1-auto-register-modules-and-endpoints
danielmackay Oct 10, 2024
da6e4af
Convert warehouse module to use endpoint discovery
danielmackay Oct 10, 2024
6e01aaf
Auto discover orders endpoints
danielmackay Oct 10, 2024
6779d7d
Auto discover customer endpoints
danielmackay Oct 10, 2024
6863f99
Auto discover catalog module endpoints
danielmackay Oct 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true

##########################################################################################
#
# CODE STYLE RULES
#
##########################################################################################

# All files
[*]
indent_style = space

# Xml files
[*.{xml,yml,json}]
indent_size = 2
tab_width = 2

# C# Projects
[*.csproj]
indent_size = 4
tab_width = 4

# C# files
[*.cs]
indent_size = 4
tab_width = 4

# New line preferences
end_of_line = lf
insert_final_newline = false

# File scoped namespaces
csharp_style_namespace_declarations = file_scoped:silent

csharp_prefer_braces = when_multiline

# https://learn.microsoft.com/en-gb/dotnet/fundamentals/code-analysis/style-rules/ide0007-ide0008
csharp_style_var_for_built_in_types = true
csharp_style_var_when_type_is_apparent = true
csharp_style_var_elsewhere = true
31 changes: 26 additions & 5 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,42 @@ on:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:

permissions:
contents: read
actions: read
checks: write

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v3
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
dotnet-version: 9.0.x

- name: Install Aspire
run: dotnet workload install aspire --include-previews

- name: Restore dependencies
run: dotnet restore

- name: Build
run: dotnet build --no-restore
run: dotnet build --no-restore -c Debug

- name: Test
run: dotnet test --no-build --verbosity normal
run: dotnet test --no-build --verbosity normal -c Debug --logger "trx;LogFileName=test-results.trx"

- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure()
with:
name: Tests Results
path: "**/test-results.trx"
reporter: dotnet-trx
20 changes: 20 additions & 0 deletions ADRs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Architectural Decision Records

## ADR1 - Ensure Related Data is Created When Seeding the DB

### Context

In normal execution of the application DB updates will cause domain events to fire. These domain events can have side affects that cause other DB updates.

There are several pieces of complicated infrastructure that make this work.

We need to ensure that related data is updated when seeding the DB via the following:

- `WarehouseDbContextInitializer`
- `CatalogDbContextInitializer`

### Decision

Instead of emulating the domain event propagating infrastructure, we will instead pass the data between initializers. This means a bit more manual work, but is a much simpler solution.

If this turns out to be too complex in future we will need to revist this.
20 changes: 20 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project>
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<GenerateDocumentationFile>true</GenerateDocumentationFile>
<!-- Remove exceptions for NUXXXX warnings -->
<NoWarn>CS1591,NU1902,NU1903,NU1904</NoWarn>

<!-- Configure code analysis. -->
<AnalysisLevel>latest</AnalysisLevel>
<!-- TODO: Upgrade to 'Recommended' -->
<AnalysisMode>Minimum</AnalysisMode>
<TreatWarningsAsErrors Condition="'$(Configuration)' == 'Release'">true</TreatWarningsAsErrors>
<CodeAnalysisTreatWarningsAsErrors Condition="'$(Configuration)' == 'Release'">true</CodeAnalysisTreatWarningsAsErrors>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>

</PropertyGroup>
</Project>
13 changes: 13 additions & 0 deletions ModularMonolith.Catalog.slnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"solution": {
"path": "ModularMonolith.sln",
"projects": [
"src\\Common\\Common.SharedKernel\\Common.SharedKernel.csproj",
"src\\Common\\Common.Tests\\Common.Tests.csproj",
"src\\Modules\\Products\\Modules.Catalog.Tests\\Modules.Catalog.Tests.csproj",
"src\\Modules\\Products\\Modules.Catalog\\Modules.Catalog.csproj",
"src\\WebApi\\WebApi.csproj",
"tools\\Database\\Database.csproj"
]
}
}
169 changes: 123 additions & 46 deletions ModularMonolith.sln

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions ModularMonolith.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Solution>
<Folder Name="/.docs/">
<File Path="README.md" />
</Folder>
<Folder Name="/.sln/">
<File Path=".editorconfig" />
<File Path="Directory.Build.props" />
</Folder>
<Folder Name="/src/">
<Project Path="src\AppHost\AppHost.csproj" Type="Classic C#" />
<Project Path="src\WebApi.Tests\WebApi.Tests.csproj" Type="Classic C#" />
<Project Path="src\WebApi\WebApi.csproj" Type="Classic C#" />
</Folder>
<Folder Name="/src/Common/">
<Project Path="src\Common\Common.ServiceDefaults\Common.ServiceDefaults.csproj" Type="Classic C#" />
<Project Path="src\Common\Common.SharedKernel\Common.SharedKernel.csproj" Type="Classic C#" />
<Project Path="src\Common\Common.Tests\Common.Tests.csproj" Type="Classic C#" />
</Folder>
<Folder Name="/src/Modules/" />
<Folder Name="/src/Modules/Catalog/">
<Project Path="src\Modules\Products\Modules.Catalog.Messages\Modules.Catalog.Messages.csproj" Type="Classic C#" />
<Project Path="src\Modules\Products\Modules.Catalog.Tests\Modules.Catalog.Tests.csproj" Type="Classic C#" />
<Project Path="src\Modules\Products\Modules.Catalog\Modules.Catalog.csproj" Type="Classic C#" />
</Folder>
<Folder Name="/src/Modules/Customers/">
<Project Path="src\Modules\Customers\Modules.Customers.Tests\Modules.Customers.Tests.csproj" Type="Classic C#" />
<Project Path="src\Modules\Customers\Modules.Customers\Modules.Customers.csproj" Type="Classic C#" />
</Folder>
<Folder Name="/src/Modules/Orders/">
<Project Path="src\Modules\Orders\Modules.Orders.Tests\Modules.Orders.Tests.csproj" Type="Classic C#" />
<Project Path="src\Modules\Orders\Modules.Orders\Modules.Orders.csproj" Type="Classic C#" />
</Folder>
<Folder Name="/src/Modules/Warehouse/">
<Project Path="src\Modules\Warehouse\Modules.Warehouse.Messages\Modules.Warehouse.Messages.csproj" Type="Classic C#" />
<Project Path="src\Modules\Warehouse\Modules.Warehouse.Tests\Modules.Warehouse.Tests.csproj" Type="Classic C#" />
<Project Path="src\Modules\Warehouse\Modules.Warehouse\Modules.Warehouse.csproj" Type="Classic C#" />
</Folder>
<Folder Name="/tools/">
<Project Path="tools\MigrationService\MigrationService.csproj" Type="Classic C#" />
</Folder>
</Solution>
48 changes: 48 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,51 @@ Responsible for Warehouse and Inventory Management
- Restocking - When do we need to restock?
- Backorders - When do we put items on back order?
- Product Management

## Business Invariants

Warehouse:
- ✅ An Aisle cannot have duplicate bays
- ✅ A bay cannot have duplicate shelves

Product Catalog:
- ✅ A product must have a name
- ✅ A product can be given one or more categories
- ✅ A product cannot have a negative price
- ✅ A product cannot duplicate categories

Customers:
- Must have a unique email address
- Must have an address

Cart:
- ✅ Must always have the correct price

Orders:
- ✅ An order must be associated with a customer
- ✅ The order total must always be correct
- ✅ The order tax must always be correct
- ✅ Shipping must be included in the total price
- ✅ Payment must be completed for the order to be placed (FUTURE: Consider splitting payments to its own module)

## Event Storming

![image](https://github.com/user-attachments/assets/63ceadd7-428e-4cac-9937-377e46ae384a)

## Bounded Contexts

### Warehouse Context

![image](https://github.com/user-attachments/assets/f7d5a522-246b-4ecf-88cf-e5cb0738f0a0)

### Catalog Context

![image](https://github.com/user-attachments/assets/a08d2964-c3fa-417f-8b6a-598d2a2fe511)

### Customer Context

![image](https://github.com/user-attachments/assets/d104aff7-2d5d-4308-af97-fca0c298d0b7)

### Orders Context

![image](https://github.com/user-attachments/assets/3c731981-1f98-42ca-9f74-c955a31a5790)
12 changes: 12 additions & 0 deletions Warehouse.slnf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"solution": {
"path": "ModularMonolith.sln",
"projects": [
"src\\Common\\Common.SharedKernel\\Common.SharedKernel.csproj",
"src\\Modules\\Warehouse\\Modules.Warehouse.Tests\\Modules.Warehouse.Tests.csproj",
"src\\Modules\\Warehouse\\Modules.Warehouse\\Modules.Warehouse.csproj",
"src\\WebApi\\WebApi.csproj",
"tools\\Database\\Database.csproj"
]
}
}
20 changes: 0 additions & 20 deletions docker-compose.yml

This file was deleted.

19 changes: 19 additions & 0 deletions src/AppHost/AppHost.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>25ad7f3b-101b-4d4c-aa10-629ae07db0e5</UserSecretsId>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\tools\MigrationService\MigrationService.csproj" />
<ProjectReference Include="..\WebApi\WebApi.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="8.2.1"/>
<PackageReference Include="Aspire.Hosting.SqlServer" Version="8.2.1" />
</ItemGroup>

</Project>
27 changes: 27 additions & 0 deletions src/AppHost/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Projects;

var builder = DistributedApplication.CreateBuilder();

var sqlServer = builder.AddSqlServer("sql-server");
var warehouseDb = sqlServer.AddDatabase("warehouse");
var catalogDb = sqlServer.AddDatabase("catalog");
var customersDb = sqlServer.AddDatabase("customers");
var ordersDb = sqlServer.AddDatabase("orders");

builder.AddProject<MigrationService>("migrations")
.WithReference(warehouseDb)
.WithReference(catalogDb)
.WithReference(customersDb)
.WithReference(ordersDb);

builder
.AddProject<WebApi>("api")
.WithExternalHttpEndpoints()
.WithReference(warehouseDb)
.WithReference(catalogDb)
.WithReference(customersDb)
.WithReference(ordersDb);

builder
.Build()
.Run();
29 changes: 29 additions & 0 deletions src/AppHost/Properties/launchSettings.json
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:17074;http://localhost:15235",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21257",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22208"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15235",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19245",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20247"
}
}
}
}
8 changes: 8 additions & 0 deletions src/AppHost/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
9 changes: 9 additions & 0 deletions src/AppHost/appsettings.json
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"
}
}
}
22 changes: 22 additions & 0 deletions src/Common/Common.ServiceDefaults/Common.ServiceDefaults.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireSharedProject>true</IsAspireSharedProject>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App"/>

<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0-preview.9.24507.7" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="8.2.1"/>
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0"/>
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0"/>
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.9.0"/>
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0"/>
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0"/>
</ItemGroup>

</Project>
Loading
Loading