Captain.Hookz 1.0.6

dotnet add package Captain.Hookz --version 1.0.6
                    
NuGet\Install-Package Captain.Hookz -Version 1.0.6
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Captain.Hookz" Version="1.0.6" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Captain.Hookz" Version="1.0.6" />
                    
Directory.Packages.props
<PackageReference Include="Captain.Hookz" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Captain.Hookz --version 1.0.6
                    
#r "nuget: Captain.Hookz, 1.0.6"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Captain.Hookz@1.0.6
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Captain.Hookz&version=1.0.6
                    
Install as a Cake Addin
#tool nuget:?package=Captain.Hookz&version=1.0.6
                    
Install as a Cake Tool

hookz3

✨ What is Hookz?

Hookz.Http adds composable lifecycle hooks (WithBefore, WithAfter, WithError) to your ASP.NET Minimal API endpoints.
It’s like middleware—but scoped, fluent, and inline.

Hookz.Http helps you:

  • Short-circuit requests

  • Inject logging, metrics, and headers

  • Clean up and finalize logic after execution

  • Chain multiple hooks per route

  • 📦 Install

dotnet add package Captain.Hookz

Supports .NET 8, and .NET 9

🚀 Usage Examples

📤 Modify response headers

app.MapGet("/data", () => Results.Ok("Payload"))
   .WithAfter(ctx =>
   {
       ctx.Response.Headers.Append("X-Processed", "true");
   });

🧠 Inject and call other services

app.MapPost("/log", () => Results.Ok("Logged"))
   .WithAfter<ILogger<Program>>(async (ctx, logger) =>
   {
	   await Task.Delay(500);
	   logger.LogInformation("POST /log handled.");
   });

🔁 Chain multiple hooks

app.MapGet("/multi", () => Results.Ok("Chained"))
   .WithBefore(ctx => Console.WriteLine("Before 1"))
   .WithBefore(ctx => Console.WriteLine("Before 2"))
   .WithAfter(ctx => Console.WriteLine("After"));

🧪 Unit-Test Friendly Hookz runs cleanly in WebApplicationFactory and supports mocking HttpContext to verify DI behavior or request filtering.

📚 Schemaless Table Helpers

The recent addition Hookz.Tables namespace introduces LogTailKey, a struct that generates lexicographically descending RowKey values based on UTC timestamps — ideal for querying the most recent records in schemaless data structures like Azure Table Storage.

🧭 Why use LogTailKey?
  • Produces sortable RowKeys that naturally order newest-to-oldest
  • Encapsulates tick math
  • Includes full conversion support:
    • ToUtc() for reverse conversion
    • Implicit conversion to/from string
    • Comparison operators
🛠️ Example Usage
using Captain.Hookz.Tables;
using Azure.Data.Tables;

var rowKey = DateTime.UtcNow.ToLogTailKey(); // extension method
var entity = new TableEntity("device-001", rowKey)
{
    ["Status"] = "Online"
};

await tableClient.AddEntityAsync(entity);

// Later, you can reverse it
DateTime originalTime = rowKey.ToUtc();


Product 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 was computed.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0

    • No dependencies.

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
1.0.6 122 7/27/2025
1.0.5 169 5/11/2025
1.0.4 139 5/11/2025
1.0.3 152 5/10/2025
1.0.2 91 5/10/2025

1.0.6 has dropped! This introduces Hookz.Tables, with the helpful LogTailKey struct. See docs to learn more!