HoneyDrunk.Kernel 0.8.0

dotnet add package HoneyDrunk.Kernel --version 0.8.0
                    
NuGet\Install-Package HoneyDrunk.Kernel -Version 0.8.0
                    
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="HoneyDrunk.Kernel" Version="0.8.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="HoneyDrunk.Kernel" Version="0.8.0" />
                    
Directory.Packages.props
<PackageReference Include="HoneyDrunk.Kernel" />
                    
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 HoneyDrunk.Kernel --version 0.8.0
                    
#r "nuget: HoneyDrunk.Kernel, 0.8.0"
                    
#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 HoneyDrunk.Kernel@0.8.0
                    
#: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=HoneyDrunk.Kernel&version=0.8.0
                    
Install as a Cake Addin
#tool nuget:?package=HoneyDrunk.Kernel&version=0.8.0
                    
Install as a Cake Tool

HoneyDrunk.Kernel

NuGet .NET 10

Runtime Implementations for the HoneyDrunk Grid - Production-ready implementations of all Kernel abstractions.

๐Ÿ“‹ What Is This?

HoneyDrunk.Kernel provides the runtime implementations of all contracts defined in HoneyDrunk.Kernel.Abstractions. This is the package you use when building executable Nodes, services, or applications that participate in the Grid.

Package Relationships:

  • HoneyDrunk.Kernel.Abstractions = Contracts only (interfaces, value types)
  • HoneyDrunk.Kernel = Real implementations, middleware, lifecycle orchestration, and bootstrapping helpers

Use this package when you want a Node to actually run inside the Grid.

๐Ÿ“ฆ What's Inside

๐ŸŒ Context Implementations

  • GridContext - Two-phase initialization: constructor sets identity (NodeId, StudioId, Environment), Initialize() sets request values (CorrelationId, CausationId, Baggage)
  • NodeContext - Process-scoped Node identity (NodeId, StudioId, Environment, version, lifecycle stage)
  • OperationContext - Per-operation tracking with timing, outcome, and metadata
  • GridContextAccessor - Reads GridContext from HttpContext.RequestServices (v0.4.0: no AsyncLocal)
  • OperationContextAccessor - Async-local accessor for ambient operation context
  • OperationContextFactory - Creates IOperationContext from current IGridContext

๐Ÿ”„ Context Mappers (v0.4.0: Static Classes)

Automatic context initialization from transport envelopes:

  • HttpContextMapper - Static methods to extract/initialize from HTTP headers
  • MessagingContextMapper - Static methods to initialize from message properties
  • JobContextMapper - Static methods to initialize from background job metadata

๐Ÿšš Transport Binders

Automatic context propagation to outgoing envelopes:

  • HttpResponseBinder - Writes Grid headers to HTTP responses
  • MessagePropertiesBinder - Writes Grid headers to message properties
  • JobMetadataBinder - Writes Grid headers to job metadata

All implement ITransportEnvelopeBinder.

โš™๏ธ Lifecycle Management

  • NodeLifecycleManager - Coordinates startup/shutdown hooks, health/readiness contributors, and lifecycle stage transitions
  • NodeLifecycleHost - IHostedService bridge that runs the lifecycle inside ASP.NET Core hosting

๐Ÿ“ˆ Diagnostics & Health

  • NoOpMetricsCollector - Zero-overhead IMetricsCollector implementation when metrics are disabled
  • NodeContextReadinessContributor - Readiness signal based on INodeContext.LifecycleStage
  • ConfigurationValidator - Validates Node configuration at startup

๐Ÿ”ง Configuration

  • StudioConfiguration - Implementation of IStudioConfiguration over IConfiguration

โค๏ธ Health

  • CompositeHealthCheck - Aggregates multiple IHealthCheck instances into a single status

๐Ÿ’‰ Dependency Injection & Bootstrapping

  • AddHoneyDrunkNode - Unified registration for all Kernel services required for a Node
  • UseGridContext - Middleware that creates and propagates GridContext for HTTP requests
  • ValidateHoneyDrunkServices - Extension that verifies Kernel services are registered correctly

๐Ÿ“ฅ Installation

dotnet add package HoneyDrunk.Kernel
<ItemGroup>
  <PackageReference Include="HoneyDrunk.Kernel" Version="0.4.0" />
</ItemGroup>

Note: This package automatically includes HoneyDrunk.Kernel.Abstractions as a dependency.

๐Ÿš€ Quick Start

Basic Node Setup

using HoneyDrunk.Kernel.Abstractions.Context;
using HoneyDrunk.Kernel.Context;
using HoneyDrunk.Kernel.Hosting;

var builder = WebApplication.CreateBuilder(args);

// Register Grid services for this Node (v0.4.0: registration guard prevents duplicate calls)
builder.Services.AddHoneyDrunkNode(options =>
{
    options.NodeId = "payment-service";
    options.StudioId = "demo-studio";
    options.Environment = "development";
    options.Version = "1.0.0";
    options.Tags["region"] = "local";
});

// v0.4.0: IGridContextAccessor is now registered automatically
// GridContext is scoped and initialized by middleware
builder.Services.AddScoped<IOperationContextFactory, OperationContextFactory>();

builder.Services.AddControllers();

var app = builder.Build();

// Fail fast if required services are missing
app.Services.ValidateHoneyDrunkServices();

// Add Grid context middleware early in the pipeline
app.UseGridContext();

app.MapControllers();

app.Run();

Using Context in Services

public class OrderService(
    IGridContext gridContext,
    IGridContextFactory gridContextFactory,
    INodeContext nodeContext,
    ILogger<OrderService> logger)
{
    public async Task ProcessOrderAsync(Order order)
    {
        logger.LogInformation(
            "Processing order {OrderId} on Node {NodeId} with correlation {CorrelationId}",
            order.Id,
            nodeContext.NodeId,
            gridContext.CorrelationId);
        
        // v0.4.0: AddBaggage mutates in-place (returns void)
        gridContext.AddBaggage("order_id", order.Id);
        
        // Create child context for downstream Node via factory
        var childContext = gridContextFactory.CreateChild(gridContext, "payment-service");
        await _paymentService.ChargeAsync(order, childContext);
    }
}

HTTP Context Mapping

// Startup - automatically maps X-Correlation-Id, X-Causation-Id, X-Baggage-* headers
app.UseGridContext();

app.MapPost("/orders", async (
    Order order,
    IGridContext gridContext,
    IOrderService orderService) =>
{
    // gridContext is populated from incoming HTTP headers or created if missing
    await orderService.ProcessOrderAsync(order);
    return Results.Created($"/orders/{order.Id}", order);
});

Lifecycle Hooks and Health

// Startup hooks
builder.Services.AddSingleton<IStartupHook, DatabaseMigrationHook>();
builder.Services.AddSingleton<IStartupHook, CacheWarmupHook>();

// Shutdown hooks
builder.Services.AddSingleton<IShutdownHook, ConnectionDrainHook>();

// Health & readiness contributors
builder.Services.AddSingleton<IHealthContributor, DatabaseHealthContributor>();
builder.Services.AddSingleton<IReadinessContributor, NodeContextReadinessContributor>();

Kubernetes can then wire probes to /health and /ready using your chosen web Node.

๐ŸŽฏ When to Use Which Package

Use HoneyDrunk.Kernel when:

  • โœ… Building an executable Node or HTTP API
  • โœ… You want AddHoneyDrunkNode() and UseGridContext()
  • โœ… You need lifecycle orchestration, health, readiness, and context mappers

Use HoneyDrunk.Kernel.Abstractions when:

  • โœ… Building a shared library used by multiple Nodes
  • โœ… You want to depend only on contracts and provide your own implementations
  • โœ… You are writing test doubles or alternative runtimes

๐Ÿ—๏ธ Architecture

Context Flow

HTTP Request with X-Correlation-Id header
    โ†“
HttpContextMapper extracts header โ†’ GridContext
    โ†“
GridContext injected into OrderService
    โ†“
OrderService creates child context for PaymentService
    โ†“
ChildContext propagates to downstream Node

Lifecycle Flow

Application Start
    โ†“
NodeLifecycleStage = Initializing
    โ†“
Execute IStartupHook instances (by priority)
    โ†“
Check IReadinessContributor instances
    โ†“
NodeLifecycleStage = Ready
    โ†“
(Application runs...)
    โ†“
Shutdown signal received
    โ†“
NodeLifecycleStage = Stopping
    โ†“
Stop accepting new requests
    โ†“
Execute IShutdownHook instances (by priority)
    โ†“
NodeLifecycleStage = Stopped

โš™๏ธ Configuration

appsettings.json

{
  "Grid": {
    "StudioId": "honeycomb-prod",
    "Environment": "production"
  },
  "Node": {
    "Id": "payment-service",
    "Sector": "financial-services",
    "Version": "2.1.0",
    "Tags": {
      "deployment-slot": "blue",
      "region": "us-east-1"
    }
  }
}

Loading Configuration

builder.Services.AddHoneyDrunkNode(options =>
{
    var node = builder.Configuration.GetSection("Node");
    
    options.NodeId = node["Id"] ?? "unknown-node";
    options.StudioId = builder.Configuration["Grid:StudioId"] ?? "default";
    options.Environment = builder.Configuration["Grid:Environment"] ?? "development";
    options.Version = node["Version"] ?? "1.0.0";
    
    // Load tags
    foreach (var tag in node.GetSection("Tags").GetChildren())
    {
        options.Tags[tag.Key] = tag.Value ?? string.Empty;
    }
});

๐Ÿ“š Documentation

See the main repository for comprehensive documentation:

๐Ÿงช Testing

See Testing Guide for patterns on:

  • Creating test contexts (GridContext, NodeContext, OperationContext)
  • Testing with real implementations vs mocks
  • Integration testing with DI
  • Testing lifecycle hooks and health contributors

๐Ÿ“„ License

This project is licensed under the MIT License.


Built with ๐Ÿฏ by HoneyDrunk Studios

GitHub โ€ข Documentation โ€ข Issues

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on HoneyDrunk.Kernel:

Package Downloads
HoneyDrunk.Vault

Secrets and configuration management library for .NET. Provides a unified abstraction for accessing secrets from multiple providers (File, Azure Key Vault, AWS Secrets Manager, Configuration, In-Memory). Integrated with HoneyDrunk.Kernel v0.8.0 for lifecycle management, health reporting, and distributed telemetry.

HoneyDrunk.Data

Provider-neutral persistence orchestration layer for HoneyDrunk.OS Grid. Complete architecture overhaul with Kernel integration for tenant resolution, correlation tracking, and telemetry enrichment. Does not depend on any specific database provider.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.8.0 1,364 5/26/2026
0.7.0 1,562 5/18/2026
0.6.0 97 5/17/2026
0.5.0 508 5/4/2026
0.4.0 1,699 1/19/2026
0.3.0 371 11/28/2025
0.2.1 232 11/22/2025
0.2.0 242 11/22/2025
0.1.2 413 11/13/2025
0.1.1 359 11/10/2025
0.1.0 166 11/7/2025

v0.8.0: Maintainability refactor (ADR-0011 follow-up). Converts AgentResultSerializer, GridContextSerializer, HttpContextMapper, JobContextMapper to static classes; drops JobContextMapper's instance constructor and unused fields. Breaking change โ€” see CHANGELOG.md.