Lightweight runtime primitives + Roslyn source generators for .NET design patterns.
Mark implementations with attributes; the generators emit keys, registries, and pipelines, and analyzers catch misuse at compile time. Overlap with libraries such as MediatR, Polly, or Stateless is fine — this project explores compile-time glue around small primitives, not a one-framework-to-rule-them-all product.
Early preview. Public APIs, generated code shapes, and
DP###diagnostics are not stable yet. Pin a package version (or a Git commit) until a stability announcement.
<PackageReference Include="Skymly.DesignPatterns" Version="0.2.4-preview1" />dotnet add package Skymly.DesignPatterns --version 0.2.4-preview1C# namespaces remain DesignPatterns.*. Full guides: Getting started · 中文文档
using DesignPatterns.Behavioral;
public interface IPaymentStrategy
{
string Pay(decimal amount);
}
[RegisterStrategy<IPaymentStrategy>("alipay")]
public sealed class AlipayPayment : IPaymentStrategy
{
public string Pay(decimal amount) => $"Alipay: {amount:C}";
}
// Generated: PaymentStrategyKeys + PaymentStrategyRegistry
var pay = PaymentStrategyRegistry.Instance.Get(PaymentStrategyKeys.Alipay);
Console.WriteLine(pay.Pay(100m));| Pattern | What you get |
|---|---|
| Singleton | [GenerateSingleton] → lazy Instance |
| Factory Registry | [RegisterFactory] → keys + registry (+ async / pooling) |
| Strategy | [RegisterStrategy] → keys + registry (+ guards / tracing) |
| Chain of Responsibility | [HandlerOrder] → ordered pipeline (+ guards / tracing) |
| Composite | [CompositePart] → catalog, forest build, traversal |
| Decorator | [Decorator] → ordered stack build |
| Event Aggregator | [RegisterEventHandler] → subscribe-all registries |
| State | [StateMachine] / [Transition] → tables, guards, hierarchy |
| Command Router | [RegisterCommandHandler] → 1:1 dispatch + optional pipeline |
| Step Builder | [GenerateBuilder] → compile-time type-state builder |
| Work Graph | [WorkGraph] / [WorkStep] → fork–join DAG waves |
Diagnostics (DP###), CodeFixes, and deeper API notes live in the documentation site and maintainer design docs.
| Resource | Purpose |
|---|---|
| DesignPatterns.Docs | User guides (EN / 中文) |
| DesignPatterns.Samples | Runnable console samples |
| ROADMAP | Backlog and exploration candidates |
| CHANGELOG | Release notes |
Issues and PRs are welcome — please use English for Issue / PR / commit text. See CONTRIBUTING.md for build, test, and module boundaries.
./build.ps1 --target Ci --configuration Release