Value Objects in C#: net10.0, validated Money, EF Core 10 complex types - #2250
Open
vladimir-pecanac-main wants to merge 1 commit into
Open
vladimir-pecanac-main wants to merge 1 commit into
vladimir-pecanac-main wants to merge 1 commit into
Conversation
Retarget both projects from net7.0 to net10.0 and move the tests from NUnit to xUnit v3 (plain Assert). Money now refuses a negative amount and stores the upper-case currency code, with the Result/Error shape and a MoneyErrors class. Add Program.cs running the article's examples in order, a PaymentsDbContext mapping Money as an EF Core 10 complex type on SQLite in memory, a Route value object with collection equality, and tests for validation, persistence and route equality (10 in total).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Updates the
domain-driven design/ValueObjectssample in place for the revised Value Objects article. The folder keeps its path, so the article's GitHub link stays valid.Changed:
ValueObjectsbecomes a console app (OutputTypeExe) and references Microsoft.EntityFrameworkCore.Sqlite.Moneyrefuses a negative amount and stores the upper-case currency code, sousdandUSDcompare equal.Create()returnsResult<Money>; the errors live in a newMoneyErrorsclass.Result.cstakes theError(Code, Description, Type)/Result/Result<TValue>shape, with aValidationerror type.Paymentgets a private constructor for EF Core.TicketPriceProviderdrops the.Value!null-forgiving operator.Assert. One equality test name is fixed.Added:
Program.cs, which runs the article's examples in the article's order.Persistence/PaymentsDbContext.cs, which mapsMoneyas an EF Core 10 complex type (SQLite in memory, so no database file is written).ValueObjects/Route.cs, a record with collection equality.MoneyValidationUnitTest(3),PersistenceUnitTest(1) andRouteEqualityUnitTest(1). There are 10 tests in total.The classic
ValueObjects.slnis unchanged. Nothing outside this folder is touched.Packages, re-queried on NuGet on 2026-09-27, the day this PR opened:
Checked locally on SDK 10.0.302, runtime 10.0.10:
dotnet build ValueObjects.sln --configuration Release: 0 warnings, 0 errorsdotnet test ValueObjects.sln --configuration Release --no-build --filter "FullyQualifiedName!~Live": 10 passed, 0 faileddotnet run --project ValueObjects: prints the output blocks the article showsdotnet list package --vulnerable --include-transitive: no vulnerable packages in either projectPlease leave this open: it merges on the day the updated article is published.