Skip to content

Aggregate Design: Order aggregate with EF Core owned types on net10.0 - #2249

Open
vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/86545-csharp-design-pattern-aggregate
Open

vladimir-pecanac-main wants to merge 1 commit into
CodeMazeBlog:mainfrom
vladimir-pecanac-main:seo/86545-csharp-design-pattern-aggregate

Conversation

@vladimir-pecanac-main

Copy link
Copy Markdown
Collaborator

Replaces the whole csharp-design-patterns/AggregateDesign sample with the follow-along build of the rewritten article. The folder keeps its path, so the article's GitHub link stays valid.

Removed: AggregateDesign.sln, AggregateDesign/ (net7.0 class library with separate OrderModel/OrderItemModel data models, AutoMapper 12.0.1 and AutoMapper.Extensions.Microsoft.DependencyInjection 12.0.0, Npgsql.EntityFrameworkCore.PostgreSQL 7.0.3 with a connection string hard-coded in OnConfiguring(), EF Core and EF Core Design 7.0.3, and three migration files) and Test/ (xunit 2.4.2, Microsoft.NET.Test.Sdk 17.3.2, coverlet.collector 3.1.2, and three tests that needed a local Postgres server). AutoMapper 12.0.1 is flagged by GHSA-rvv3-g6hj-g44x (NU1903 on restore); the sample no longer needs a mapping library at all.

Added:

  • AggregateDesign.Domain/: the Order aggregate root and its OrderItem entity (private setters, private _items field, private constructor plus Create(TimeProvider)), Result and OrderErrors for broken rules, and IOrderRepository. The item methods lock once payment starts and quantities are int, so the paid amount can never exceed the total on any path.
  • AggregateDesign.Infrastructure/: OrdersDbContext mapping the aggregate directly with OwnsMany(), and OrderRepository (load tracked, change through the root, SaveChangesAsync()).
  • AggregateDesign.Tests/: 12 domain tests and 3 repository tests on in-memory SQLite that read back through a fresh DbContext. xUnit v3 with plain Assert, one hand-written FixedClock.
  • AggregateDesign.sln (classic format, so CI finds it). No database file is written, so no folder .gitignore is needed.

Packages, re-queried on NuGet on 2026-09-27, the day this PR opened:

  • Microsoft.EntityFrameworkCore 10.0.12
  • Microsoft.EntityFrameworkCore.Sqlite 10.0.12
  • Microsoft.NET.Test.Sdk 18.10.1
  • xunit.v3.mtp-off 4.0.1
  • xunit.runner.visualstudio 4.0.0

Checked locally on SDK 10.0.302, runtime 10.0.10:

  • dotnet build AggregateDesign.sln -c Release --no-incremental: 0 warnings, 0 errors
  • dotnet test AggregateDesign.sln --filter "FullyQualifiedName!~Live": 15 of 15 passed
  • dotnet list package --vulnerable --include-transitive: none on all three projects

Only files under csharp-design-patterns/AggregateDesign/ change.

Replace the net7.0 sample with the article's follow-along solution:
AggregateDesign.Domain (Order aggregate, Result and OrderErrors,
IOrderRepository), AggregateDesign.Infrastructure (EF Core 10.0.12
OwnsMany mapping, OrderRepository) and AggregateDesign.Tests (12 domain
tests, 3 repository tests on in-memory SQLite, xUnit v3).

The item methods now lock once payment starts, quantities are int, and
the repository saves tracked changes instead of attaching a mapped copy.
Removes AutoMapper, the Npgsql provider with its hard-coded connection
string, and the migrations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant