diff --git a/docs/samples.md b/docs/samples.md index ad4a679..0824c08 100644 --- a/docs/samples.md +++ b/docs/samples.md @@ -27,7 +27,7 @@ CI checks out both repositories so the sibling path `../DesignPatterns` resolves | Sample | Demonstrates | |--------|--------------| -| **DesignPatterns.Samples.Strategy** | `[RegisterStrategy]` → Keys + static `Instance` | +| **DesignPatterns.Samples.Strategy** | `[RegisterStrategy]` → Keys + static `Instance`; sync pay + async `ExecuteAsync` | | **DesignPatterns.Samples.Chain** | `[HandlerOrder]` → handler pipeline | | **DesignPatterns.Samples.Composite** | `[CompositePart]` → `BuildForest()` / `TraverseForest` (+ manual builder) | | **DesignPatterns.Samples.Factory** | `[RegisterFactory]` generated registry | diff --git a/docs/strategy.md b/docs/strategy.md index ddb4f4f..f585904 100644 --- a/docs/strategy.md +++ b/docs/strategy.md @@ -26,6 +26,23 @@ public static partial class PaymentStrategyRegistry { } Optional marker interfaces: `IStrategy`, `IAsyncStrategy` — not required by the generator. +## Async resolution + +`IAsyncStrategy` contracts use the same Keys / Registry / `RegisterDi` pipeline. `StrategyRegistryExtensions` adds `ExecuteAsync` and `TryExecuteAsync`: + +```csharp +public interface ITextProcessor : IAsyncStrategy { } + +// Registry value is IAsyncStrategy +await registry.ExecuteAsync(key, input); + +// Derived contract (specify TContract, TOutput, TInput) +await registry.ExecuteAsync(TextProcessorKeys.Length, "hello"); + +// Equivalent +await registry.Get(TextProcessorKeys.Length).ExecuteAsync("hello"); +``` + ## Diagnostics DP003–DP007 — duplicate keys, contract mismatch, unregistered types, missing ctor. diff --git a/docs/zh/samples.md b/docs/zh/samples.md index 2c484b6..601322f 100644 --- a/docs/zh/samples.md +++ b/docs/zh/samples.md @@ -25,7 +25,7 @@ dotnet run --project DesignPatterns.Samples.Strategy -c Release | 示例 | 演示内容 | |------|----------| -| **DesignPatterns.Samples.Strategy** | `[RegisterStrategy]` → Keys + `Instance` | +| **DesignPatterns.Samples.Strategy** | `[RegisterStrategy]` → Keys + `Instance`;同步支付 + 异步 `ExecuteAsync` | | **DesignPatterns.Samples.Chain** | `[HandlerOrder]` 管道 | | **DesignPatterns.Samples.Composite** | `[CompositePart]` + `BuildForest()` / `TraverseForest`(含手动 builder) | | **DesignPatterns.Samples.Factory** | 生成器工厂注册表 | diff --git a/docs/zh/strategy.md b/docs/zh/strategy.md index 40992c8..f492981 100644 --- a/docs/zh/strategy.md +++ b/docs/zh/strategy.md @@ -19,6 +19,23 @@ 可选标记接口:`IStrategy`、`IAsyncStrategy` — 生成器不强制要求。 +## 异步解析 + +`IAsyncStrategy` 契约复用同一套 Keys / Registry / `RegisterDi`。`StrategyRegistryExtensions` 提供 `ExecuteAsync` / `TryExecuteAsync`: + +```csharp +public interface ITextProcessor : IAsyncStrategy { } + +// 注册表值为 IAsyncStrategy +await registry.ExecuteAsync(key, input); + +// 派生契约(显式指定 TContract、TOutput、TInput) +await registry.ExecuteAsync(TextProcessorKeys.Length, "hello"); + +// 等价写法 +await registry.Get(TextProcessorKeys.Length).ExecuteAsync("hello"); +``` + ## 诊断 DP003–DP007 — 见 [诊断](./diagnostics.md)。