HoneyDrunk.Kernel
0.8.0
dotnet add package HoneyDrunk.Kernel --version 0.8.0
NuGet\Install-Package HoneyDrunk.Kernel -Version 0.8.0
<PackageReference Include="HoneyDrunk.Kernel" Version="0.8.0" />
<PackageVersion Include="HoneyDrunk.Kernel" Version="0.8.0" />
<PackageReference Include="HoneyDrunk.Kernel" />
paket add HoneyDrunk.Kernel --version 0.8.0
#r "nuget: HoneyDrunk.Kernel, 0.8.0"
#:package HoneyDrunk.Kernel@0.8.0
#addin nuget:?package=HoneyDrunk.Kernel&version=0.8.0
#tool nuget:?package=HoneyDrunk.Kernel&version=0.8.0
HoneyDrunk.Kernel
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
IOperationContextfrom currentIGridContext
๐ 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 -
IHostedServicebridge that runs the lifecycle inside ASP.NET Core hosting
๐ Diagnostics & Health
- NoOpMetricsCollector - Zero-overhead
IMetricsCollectorimplementation when metrics are disabled - NodeContextReadinessContributor - Readiness signal based on
INodeContext.LifecycleStage - ConfigurationValidator - Validates Node configuration at startup
๐ง Configuration
- StudioConfiguration - Implementation of
IStudioConfigurationoverIConfiguration
โค๏ธ Health
- CompositeHealthCheck - Aggregates multiple
IHealthCheckinstances 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()andUseGridContext() - โ 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;
}
});
๐ Related Packages
- HoneyDrunk.Kernel.Abstractions - Contracts only
- HoneyDrunk.Standards - Analyzers and coding conventions
๐ Documentation
See the main repository for comprehensive documentation:
- Complete File Guide - Architecture documentation
- Bootstrapping Guide - Unified Node initialization
- Context Guide - Context propagation patterns
- Lifecycle Guide - Lifecycle orchestration
- Implementations Guide - Runtime implementation details
- Transport Guide - Context propagation across boundaries
- Testing Guide - Test patterns and best practices
๐งช 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 | Versions 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. |
-
net10.0
- HoneyDrunk.Kernel.Abstractions (>= 0.8.0)
- Ulid (>= 1.4.1)
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.
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.