Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ if (parser.Execute("123", out var value))

PatternKit will ultimately support the full spectrum of **creational**, **structural**, and **behavioral** patterns:

| Category | Patterns ✓ = Implemented |
| -------------- |------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **Creational** | [Factory](xref:PatternKit.Creational) (planned) • [Builder](xref:PatternKit.Creational.Builder) (planned) • Prototype (planned) • Singleton (planned) |
| **Structural** | Adapter (planned) • Bridge (planned) • Composite (planned) • Decorator (planned) • Facade (planned) • Flyweight (planned) • Proxy (planned) |
| Category | Patterns ✓ = Implemented |
| -------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| **Creational** | Factory (planned) • [Builder](xref:PatternKit.Creational.Builder) (planned) • Prototype (planned) • Singleton (planned) |
| **Structural** | Adapter (planned) • Bridge (planned) • Composite (planned) • Decorator (planned) • Facade (planned) • Flyweight (planned) • Proxy (planned) |
| **Behavioral** | [Strategy](xref:PatternKit.Behavioral.Strategy.Strategy`2) ✓ • [TryStrategy](xref:PatternKit.Behavioral.Strategy.TryStrategy`2) ✓ • Chain of Responsibility (planned) • Command (planned) • Iterator (planned) • Mediator (planned) • Memento (planned) • Observer (planned) • State (planned) • Template Method (planned) • Visitor (planned) |

Each pattern ships with:
Expand Down Expand Up @@ -98,14 +98,3 @@ public class StrategyTests : TinyBddXunitBase
}
```

---

## 🔗 Explore the API

* [Behavioral Patterns](xref:PatternKit.Behavioral)
* [Creational Patterns](xref:PatternKit.Creational)
* [Structural Patterns](xref:PatternKit.Structural)
* [Common Utilities](xref:PatternKit.Common)

> **Tip:** Use the search bar in the left navigation panel to quickly find classes, methods, and examples.

15 changes: 4 additions & 11 deletions src/PatternKit.Examples/Chain/AuthLoggingDemo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@ namespace PatternKit.Examples.Chain;
/// </remarks>
public readonly record struct HttpRequest(string Method, string Path, IReadOnlyDictionary<string, string> Headers);

/// <summary>
/// Minimal HTTP-ish response. Included for completeness; not used by this specific demo.
/// </summary>
/// <param name="Status">HTTP status code.</param>
/// <param name="Body">Payload body (if any).</param>
public readonly record struct HttpResponse(int Status, string Body);

/// <summary>
/// Demonstrates an <see cref="ActionChain{T}"/> over <see cref="HttpRequest"/> that composes
/// request-id logging and an auth gate for <c>/admin/*</c> without <c>if</c>/<c>else</c> ladders.
Expand All @@ -32,19 +25,19 @@ namespace PatternKit.Examples.Chain;
/// <item>
/// <description>
/// <b>Conditional log (continue):</b> If <c>X-Request-Id</c> is present,
/// log <c>reqid=&lt;id&gt;</c> and <i>continue</i> (via <see cref="ActionChain{T}.ThenContinue(System.Action{T})"/>).
/// log <c>reqid=&lt;id&gt;</c> and <i>continue</i> (via <see cref="ActionChain{T}.Builder.WhenBuilder.ThenContinue(System.Action{T})"/>).
/// </description>
/// </item>
/// <item>
/// <description>
/// <b>Auth gate (stop):</b> If the path starts with <c>/admin</c> and no <c>Authorization</c> header exists,
/// log <c>deny: missing auth</c> and <i>stop</i> the chain early
/// (via <see cref="ActionChain{T}.ThenStop(System.Action{T})"/>).
/// (via <see cref="ActionChain{T}.Builder.WhenBuilder.ThenStop(System.Action{T})"/>).
/// </description>
/// </item>
/// <item>
/// <description>
/// <b>Tail log (finally-on-continue):</b> In <see cref="ActionChain{T}.Finally(System.Action{T, Action{T}})"/>
/// <b>Tail log (finally-on-continue):</b> In <see cref="ActionChain{T}.Builder.Finally"/>
/// we log <c>{Method} {Path}</c>. This <em>runs only if no prior step called <c>ThenStop</c></em>
/// (strict-stop semantics). In other words, a <c>Stop</c> short-circuits the chain and
/// prevents this tail from running.
Expand Down Expand Up @@ -113,7 +106,7 @@ public static List<string> Run()
// admin requires auth (stop)
.When(static (in r) => r.Path.StartsWith("/admin", StringComparison.Ordinal)
&& !r.Headers.ContainsKey("Authorization"))
.ThenStop(r => log.Add("deny: missing auth"))
.ThenStop(_ => log.Add("deny: missing auth"))

// tail log (runs only if the chain wasn't stopped earlier)
.Finally((in r, next) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<RootNamespace>PatternKit.Generators</RootNamespace>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<ProduceReferenceAssembly>true</ProduceReferenceAssembly>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public async Task Build_Snapshot_Immutability()
})
.Then("P1 has 1 pair; P2 has 2 pairs", t =>
{
Assert.Equal(1, t.P1.Preds.Length);
Assert.Equal(1, t.P1.Handlers.Length);
Assert.Single(t.P1.Preds);
Assert.Single(t.P1.Handlers);
Assert.Equal(2, t.P2.Preds.Length);
Assert.Equal(2, t.P2.Handlers.Length);

Expand Down
Loading