Patterns
Welcome! This section is the reference home for PatternKit’s core building blocks. Each page explains the why, the shape (APIs), and gives a tiny snippet so you can drop the pattern straight into your codebase.
If you’re looking for end-to-end, production-shaped demos, check the Examples & Demos section—those pages show these patterns working together (auth/logging chains, payment pipelines, router, coercer, etc.).
How these fit together
Behavioral patterns describe what runs & when (chains and strategies, observers, mediators, state machines).
Creational helpers build immutable, fast artifacts (routers, pipelines) from tiny delegates.
Common themes:
- First-match wins (predictable branching without
ifladders). - Branchless rule packs (
ActionChain<T>withWhen/ThenContinue/ThenStop/Finally). - Immutable after
Build()(thread-safe, allocation-light hot paths).
- First-match wins (predictable branching without
Behavioral
Chain
Behavioral.Chain.ActionChain Compose linear rule packs with explicit continue/stop semantics and an always-runs
Finally.Behavioral.Chain.ResultChain Like
ActionChain, but each step returns a result; first failure short-circuits.
Strategy
Behavioral.Strategy.Strategy Simple strategy selection—pick exactly one handler.
Behavioral.Strategy.TryStrategy First-success wins: chain of
Try(in, out)handlers; great for parsing/coercion.Behavioral.Strategy.ActionStrategy Fire one or more actions (no result value) based on predicates.
Behavioral.Strategy.AsyncStrategy Async sibling for strategies that await external work.
Template
Behavioral.Template.TemplateMethod Abstract base with
OnBefore/Step/OnAfterhooks and optional synchronization.Behavioral.Template.Template (Fluent) Fluent, allocation-light template with multicast hooks and
TryExecute.Behavioral.Template.AsyncTemplate (Fluent) Async fluent sibling with cancellation-aware hooks and
TryExecuteAsync.
Iterator
- Behavioral.Iterator.ReplayableSequence
Forkable, lookahead, on-demand buffered sequence with immutable struct cursors, speculative forks, and LINQ interop (pay-as-you-go buffering). - Behavioral.Iterator.WindowSequence
Sliding / striding window iterator with optional partial trailing window and buffer reuse for zero-allocation full windows.
Mediator
Command
Observer
State
- Behavioral.State.StateMachine
Fluent, generic state machine with entry/exit hooks and transition effects; immutable after
Build().
Interpreter
- Behavioral.Interpreter Parse and evaluate domain-specific languages with composable expression trees.
Creational (Builder)
Creational.AbstractFactory Family-aware factory that produces related objects with consistent themes.
Creational.Builder.BranchBuilder Zero-
ifrouter: register(predicate → step)pairs; emits a tight first-match loop.Creational.Builder.ChainBuilder Small helper to accumulate steps, then project into your own pipeline type.
Creational.Builder.Composer Compose multiple builders/artifacts into a single product.
Creational.Builder.MutableBuilder A lightweight base for fluent, mutable configuration objects.
Creational.Factory Key → creator mapping with optional default; immutable and allocation-light.
Creational.ObjectPool Bounded, lease-based reuse for expensive resettable resources.
Creational.Prototype Clone-and-tweak via fluent builders and keyed registries.
Creational.Singleton Fluent, thread-safe singleton with lazy/eager modes and init hooks.
Structural
Structural.Adapter.Adapter Fluent in-place mapping with ordered validation for DTO projection.
Structural.Bridge.Bridge Abstraction/implementation split with fluent pre/post hooks and validations.
Structural.Composite.Composite Uniform treatment of leaves and compositions via seed+combine folding.
Structural.Decorator.Decorator Fluent wrapping with before/after/around hooks and composition.
Structural.Facade.Facade Unified subsystem interface with named operations.
Structural.Flyweight Identity sharing for high-volume immutable instances.
Structural.Proxy Virtual/protection/logging/caching/remote proxies.
Additional Patterns
Messaging In-process messaging primitives and source-generated dispatchers for application flows that are not durable broker responsibilities.
Message Envelope and Context Immutable payload envelopes, headers, and execution context for enterprise integration patterns.
Enterprise Message Routing Content router, recipient list, splitter, and aggregator primitives for deterministic in-process flows.
Routing Slip Runtime and source-generated ordered itineraries that record message progress in headers.
Saga / Process Manager Runtime and source-generated process managers for typed message transitions over explicit state.
Mailbox Serialized in-process inboxes with bounded backpressure, error policy, and shutdown behavior.
Idempotent Receiver, Inbox, and Outbox Pluggable idempotency stores, inbox boundaries, and outbox records for at-least-once message handling.
Enterprise Integration Source Generators Compile-time generated content-router, routing-slip, and saga factories with explicit diagnostics.
TypeDispatcher Type-safe runtime dispatch that routes objects to handlers based on their concrete type.
Where to see them in action
- Auth & Logging Chain — request-ID logging + strict auth short-circuit using
ActionChain. - Strategy-Based Coercion —
TryStrategyturns mixed inputs into typed values. - Mediated / Config-Driven Transaction Pipelines — chains + strategies for totals, rounding, tender routing.
- Minimal Web Request Router —
BranchBuilderfor middleware and routes. - State Machine — order lifecycle with entry/exit hooks and default behaviors.
Tip: every pattern page has a tiny example; the demos show realistic combinations with TinyBDD tests you can read like specs.