PatternKit.Examples
0.8.2
See the version list below for details.
dotnet add package PatternKit.Examples --version 0.8.2
NuGet\Install-Package PatternKit.Examples -Version 0.8.2
<PackageReference Include="PatternKit.Examples" Version="0.8.2" />
<PackageVersion Include="PatternKit.Examples" Version="0.8.2" />
<PackageReference Include="PatternKit.Examples" />
paket add PatternKit.Examples --version 0.8.2
#r "nuget: PatternKit.Examples, 0.8.2"
#:package PatternKit.Examples@0.8.2
#addin nuget:?package=PatternKit.Examples&version=0.8.2
#tool nuget:?package=PatternKit.Examples&version=0.8.2
PatternKit
Fluent Design Patterns for Modern .NET
Elegant, declarative, allocation-light implementations of classic patterns—optimized for .NET 9.
✨ Overview
PatternKit is a modern library that reimagines the GoF design patterns for .NET 9+.
Instead of boilerplate-heavy class hierarchies, we favor:
- Fluent builders and DSLs (chainable, declarative, composable).
- Source generators to eliminate reflection and runtime overhead.
- Zero-allocation hot paths for performance-critical scenarios.
- Strong typing with
inparameters, avoiding boxing and defensive copies. - Testable, deterministic APIs that pair naturally with BDD and xUnit/NUnit/MSTest.
Our goal: make patterns a joy to use, not a chore to implement.
🚀 Quick Start
Install via NuGet:
dotnet add package PatternKit --version <latest>
Use a pattern immediately—here’s a simple Strategy:
using PatternKit.Behavioral.Strategy;
var classify = Strategy<int, string>.Create()
.When(i => i > 0).Then(i => "positive")
.When(i => i < 0).Then(i => "negative")
.Default(_ => "zero")
.Build();
Console.WriteLine(classify.Execute(5)); // positive
Console.WriteLine(classify.Execute(-3)); // negative
Console.WriteLine(classify.Execute(0)); // zero
Or a TryStrategy for first-match-wins pipelines:
var parse = TryStrategy<string, int>.Create()
.Always((in string s, out int r) => int.TryParse(s, out r))
.Finally((in string _, out int r) => { r = 0; return true; })
.Build();
if (parse.Execute("123", out var n))
Console.WriteLine(n); // 123
📦 Patterns (Planned & In Progress)
PatternKit will grow to cover Creational, Structural, and Behavioral patterns with fluent, discoverable APIs:
| Category | Patterns ✓ = implemented |
|---|---|
| Creational | Factory ✓ • Composer ✓ • ChainBuilder ✓ • BranchBuilder ✓ • MutableBuilder ✓ • Prototype ✓ • Singleton ✓ |
| Structural | Adapter ✓ • Bridge ✓ • Composite ✓ • Decorator (planned) • Facade (planned) • Flyweight (planned) • Proxy (planned) |
| Behavioral | Strategy ✓ • TryStrategy ✓ • ActionStrategy ✓ • ActionChain ✓ • ResultChain ✓ • Command ✓ • Iterator (planned) • Mediator ✓ • Memento (planned) • Observer (planned) • State (planned) • Template Method (planned) • Visitor (planned) |
Each pattern will ship with:
- A fluent API (
.When(...),.Then(...),.Finally(...), etc.) - Source-generated boilerplate where possible.
- DocFX-ready documentation and TinyBDD tests.
🧪 Testing Philosophy
All patterns are validated with TinyBDD and xUnit:
[Feature("Strategy")]
public class StrategyTests : TinyBddXunitBase
{
[Scenario("Positive/negative classification")]
[Fact]
public async Task ClassificationWorks()
{
await Given("a strategy with three branches", BuildStrategy)
.When("executing with 5", s => s.Execute(5))
.Then("result should be 'positive'", r => r == "positive")
.AssertPassed();
}
}
We keep tests behavior-driven, readable, and high coverage.
💡 Design Goals
- Declarative: Favor expression-based and fluent APIs over imperative setup.
- Minimalism: Prefer single-responsibility types and low ceremony.
- Performance: Allocation-free handlers,
inparameters, ahead-of-time friendly. - Discoverability: IntelliSense-first APIs; easy to read, easy to write.
- Testability: TinyBDD integration and mocks built-in where applicable.
🛠 Requirements
- .NET 9.0 or later (we use
inparameters and modern generic features). - C# 12 features enabled (
readonly struct, static lambdas, etc.).
📚 Documentation
Full API documentation is published with DocFX (coming soon). Each type and member ships with XML docs, examples, and cross-links between patterns.
🤝 Contributing
We welcome issues, discussions, and PRs. Focus areas:
- Adding new patterns (start with Behavioral for max impact)
- Improving fluent builder syntax and source generator coverage
- Writing TinyBDD test scenarios for edge cases
📄 License
MIT — see LICENSE for details.
❤️ Inspiration
PatternKit is inspired by:
- The Gang of Four design patterns
- Fluent APIs from ASP.NET Core, System.Linq, and modern libraries
- The desire to make patterns readable, performant, and fun to use in 2025+
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- JetBrains.Annotations (>= 2025.2.2)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.9)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.9)
- Microsoft.Extensions.Options (>= 9.0.9)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.9)
- Microsoft.Extensions.Options.DataAnnotations (>= 9.0.9)
- PatternKit.Core (>= 0.8.2)
- PatternKit.Generators (>= 0.8.2)
-
net9.0
- JetBrains.Annotations (>= 2025.2.2)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.9)
- Microsoft.Extensions.Configuration.Binder (>= 9.0.9)
- Microsoft.Extensions.Options (>= 9.0.9)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 9.0.9)
- Microsoft.Extensions.Options.DataAnnotations (>= 9.0.9)
- PatternKit.Core (>= 0.8.2)
- PatternKit.Generators (>= 0.8.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.17.3 | 350 | 12/11/2025 |
| 0.17.2 | 350 | 12/11/2025 |
| 0.17.1 | 356 | 12/11/2025 |
| 0.17.0 | 390 | 11/18/2025 |
| 0.16.2 | 190 | 10/29/2025 |
| 0.16.1 | 180 | 10/28/2025 |
| 0.16.0 | 174 | 10/12/2025 |
| 0.15.0 | 154 | 10/10/2025 |
| 0.14.0 | 174 | 10/9/2025 |
| 0.13.0 | 166 | 10/8/2025 |
| 0.12.0 | 166 | 10/8/2025 |
| 0.11.0 | 170 | 10/7/2025 |
| 0.10.0 | 170 | 10/7/2025 |
| 0.9.0 | 170 | 9/23/2025 |
| 0.8.2 | 170 | 9/23/2025 |
| 0.8.1 | 199 | 9/20/2025 |
| 0.8.0 | 299 | 9/17/2025 |
| 0.7.0 | 309 | 9/16/2025 |
| 0.6.0 | 299 | 9/16/2025 |
| 0.5.0 | 309 | 9/16/2025 |
| 0.4.0 | 308 | 9/16/2025 |
| 0.3.3 | 301 | 9/16/2025 |
| 0.1.1 | 163 | 9/12/2025 |