Skip to content

entelect-incubator/.NET-Toolbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

.NET Toolbox

Build CodeQL License: MIT .NET 10

A curated, production-grade collection of C# design patterns, architectural patterns, and .NET reference implementations. Each module demonstrates one or more patterns in a self-contained, buildable, test-covered exampleβ€”ready to lift into real projects.


Contents

# Module Patterns & Concepts Key tech
4 Utilities Result, CQRS, Static FaΓ§ade, Provider Pattern Result pattern, MediatorLite, Static Logger, FluentValidation, OpenTelemetry, Serilog
5 PaymentSaga Saga, Eventual Consistency, Event Sourcing, Retry MassTransit SAGA, RabbitMQ, EF Core, .NET Aspire, OpenTelemetry

Philosophy

  • Result Pattern β€” Typed success/failure returns, no exceptions for control flow.
  • Clean Architecture β€” Domain β†’ Application β†’ Infrastructure β†’ API. Dependencies only flow inward.
  • CQRS β€” Commands and Queries separated via lightweight MediatorLite dispatcher, fully testable.
  • Eventual Consistency β€” Saga pattern for long-running workflows across service boundaries.
  • Observable by Default β€” Serilog structured logging + OpenTelemetry on every module.
  • Provider Pattern β€” Abstract DateTime and Guid creation for deterministic tests.
  • Explicit Over Implicit β€” No magic, every pattern is readable, traceable, and refactorable.

4. Utilities

Shared library demonstrating Result Pattern, CQRS, and Provider Pattern.

Utilities/
  Results/          Result<T>, Result β€” typed success/failure with ErrorResults enum
  CQRS/             ICommand, IQuery, Dispatcher β€” command/query segregation
  Logging/Static/   Logger β€” static faΓ§ade over Serilog for cross-cutting concerns
  Enums/            ErrorResults β€” centralized domain error codes
  Extensions/       Common extension methods and operators
  Helpers/          API response mappers (Result β†’ HTTP status)
  Middleware/       Logging middleware for request/response tracing
  Providers/        DateTimeOffset + Guid β€” injectable, mockable factories

5. PaymentSaga

Reference implementation of the Saga Pattern for long-running, eventually-consistent workflows.

Patterns demonstrated:

  • Saga State Machine β€” Multi-step process with external gates (approval, payment, settlement)
  • Event-Driven Architecture β€” MassTransit pub/sub + RabbitMQ message transport
  • Retry & DLQ β€” Resilient consumer implementations with exponential backoff
  • Repository Pattern β€” EF Core data access with concurrent saga state via RowVersion
  • Validation Rules β€” FluentValidation at entry point, domain guards in entities
  • CQRS + Domain Events β€” Commands trigger sagas; queries read via DTO projection

Running all tests

dotnet test --configuration Release --logger "console;verbosity=normal"

See 5.PaymentSaga/DEV.md for full architecture docs, Mermaid diagrams, and system analysis.

Quick start (requires Docker Desktop):

dotnet run --project 5.PaymentSaga/src/PaymentSaga.AppHost

Testing

Every pattern module includes:

  • Unit tests β€” NUnit with NSubstitute mocks and Bogus fake data generators
  • Architecture tests β€” NetArchTest to enforce Clean Architecture layer boundaries
  • Builders β€” Faker patterns for consistent test data generation

Example test directory:

PaymentSaga.Tests/
  Builders/         Bogus fakers for domain entities and commands
  Domain/           Domain entity & value object tests
  Application/      Handler, validator, CQRS tests with mocked I/O
  Architecture/     Layer dependency rules and naming conventions

Security

  • Static analysis via CodeQL on every push and PR.
  • NuGet dependencies are kept up to date automatically via Dependabot (weekly, Mondays).
  • See SECURITY.md if you discover a vulnerability.

Contributing

Each module must demonstrate one or more C# design patterns clearly and completely.

  1. Architecture: Follow Clean Architecture (Domain β†’ Application β†’ Infrastructure β†’ API)
  2. Testing: 100% coverage of patterns; use builders, mocks (NSubstitute), and architecture tests
  3. Documentation: Include a DEV.md with Mermaid diagrams (C4, state machine, sequence, etc.)
  4. Code Style: Follow conventions in each module's .github/copilot-instructions.md
  5. Gates: All PRs must pass build.yml + codeql.yml

About

.NET-Toolbox – A curated collection of cool .NET samples, tools, and resources. πŸš€ Covering modern C#, ASP.NET, EF Core, OpenAPI, MediatR, and more. Stay up-to-date with best practices, patterns, and handy utilities! πŸ’‘πŸ”§

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages