Muonroi.Core 1.0.0-alpha.16

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

Muonroi.Core

Foundational runtime services — datetime, JSON serialization, execution context, clock providers, sequential GUIDs, and configuration helpers — shared across all Muonroi applications.

NuGet License: Apache 2.0

Muonroi.Core implements the contracts declared in Muonroi.Core.Abstractions and wires them into the ASP.NET Core DI container with a single call. It covers the low-level concerns that every service needs before it can do anything useful: an injectable clock, a testable JSON serializer, an ambient execution context that carries tenant/user/correlation data, database-portable sequential GUIDs, cryptography-aware configuration reading, and opinionated Redis and pagination binding. It also pulls in Muonroi structured logging via Muonroi.Logging.

Installation

dotnet add package Muonroi.Core --prerelease

Quick Start

Call AddCoreServices once during startup. The sample below is taken directly from samples/Quickstart.Core/src/Quickstart.Core.Api/Program.cs:

using Muonroi.Core.Extensions;

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);

builder.Services.AddCoreServices(
    builder.Configuration,
    isSecretDefault: true,   // true = config values are read as-is (no decryption)
    secretKey: string.Empty, // decryption key — empty when isSecretDefault is true
    paginationConfigs: null, // null = bound from appsettings with safe defaults
    tokenConfig: null);      // null = bound from appsettings

builder.Services.AddControllers();
WebApplication app = builder.Build();
app.MapControllers();
app.Run();

Inject the registered services anywhere:

public sealed class CoreDemoController(
    IMDateTimeService dateTime,
    IMJsonSerializeService json,
    ISystemExecutionContextAccessor contextAccessor) : ControllerBase
{
    [HttpGet("now")]
    public IActionResult Now() =>
        Ok(new { now = dateTime.Now(), utcNow = dateTime.UtcNow(), nowTs = dateTime.NowTs() });

    [HttpPost("json-roundtrip")]
    public IActionResult JsonRoundtrip([FromBody] SamplePayload payload)
    {
        string serialized = json.Serialize(payload);
        SamplePayload? result = json.Deserialize<SamplePayload>(serialized);
        return Ok(new { serialized, result });
    }
}

Features

  • Single-call DI registrationAddCoreServices() registers all foundational singletons in one call; AddRedisConfiguration() is available separately if you only need Redis binding.
  • Testable clock abstractionIMDateTimeService (implementation: MDateTimeService) exposes Now(), UtcNow(), Today(), UtcToday(), NowTs(), UtcNowTs() so controllers and services never call DateTime.Now directly.
  • Pluggable static clockClock static class delegates to a swappable IClockProvider. Built-in providers: ClockProviders.Utc, ClockProviders.Local, ClockProviders.Unspecified.
  • JSON serialization wrapperIMJsonSerializeService wraps System.Text.Json with IgnoreCycles and WhenWritingDefault options. JsonExtensions.Serialize(this object) provides an extension-method shortcut.
  • Ambient execution contextISystemExecutionContextAccessor + ISystemExecutionContext carry tenant ID, user ID, username, correlation ID, auth token, API key, permissions, and source type without threading them through every method signature.
  • Sequential GUID generationMSequentialGuidGenerator.Instance.Create() produces time-ordered GUIDs suited for SQL Server (sequential at end), Oracle (sequential as binary), MySQL/PostgreSQL (sequential as string).
  • Configuration helpersIConfiguration.GetOptions<T>(section), ConfigureStartupConfig<TConfig>(), ConfigureDictionary<TOptions>(), and GetConfigHelper() / GetCryptConfigValue() for transparent AES decryption when EnableEncryption: true is set.
  • Pagination config bindingMPaginationConfig is bound from appsettings.json and enforces DefaultPageIndex ≥ 1 and DefaultPageSize ≥ 15 automatically.
  • String utilitiesMStringExtension exposes NormalizeString() (accent removal, to-lowercase), DecryptConfigurationValue(), and related helpers.
  • Structured logging — registers Muonroi logging via AddMuonroiLogging() (from Muonroi.Logging).
  • Problem Details — registers AddProblemDetails() and AddHttpContextAccessor() as part of the standard setup.

Configuration

appsettings.json sections

AddCoreServices binds three optional sections. All have safe defaults if the section is absent.

{
  "RedisConfigs": {
    "Host": "localhost",
    "Port": "6379",
    "Password": "",
    "KeyPrefix": "myapp"
  },
  "PaginationConfigs": {
    "DefaultPageIndex": 1,
    "DefaultPageSize": 20,
    "MaxPageSize": 100
  },
  "JwtConfigs": {
    "Issuer": "https://auth.example.com",
    "Audience": "myapp",
    "SecretKey": "..."
  }
}

Encrypted configuration values

Set EnableEncryption: true and SecretKey: <key> at the configuration root to have GetConfigHelper() / GetCryptConfigValue() decrypt AES-encrypted values transparently.

Registering only Redis

services.AddRedisConfiguration(configuration, isSecretDefault: true, secretKey: "");

Registering typed pagination config

services.AddPaginationConfigs(configuration, new MyPaginationConfig());

Swapping the static clock provider

Clock.Provider = ClockProviders.Utc; // or ClockProviders.Local

API Reference

Type Purpose
CoreServiceCollectionExtensions.AddCoreServices() Registers all foundational singletons; entry point for DI setup
CoreServiceCollectionExtensions.AddRedisConfiguration() Standalone Redis config binding with optional decryption
IMDateTimeService / MDateTimeService Injectable date/time service: Now(), UtcNow(), Today(), UtcToday(), NowTs(), UtcNowTs()
Clock Static clock façade; provider is set via Clock.Provider
IClockProvider Contract for clock providers; built-ins: UtcClockProvider, LocalClockProvider, UnspecifiedClockProvider
ClockProviders Static properties Utc, Local, Unspecified
IMJsonSerializeService DI-friendly JSON serializer/deserializer
JsonExtensions.Serialize() object.Serialize() extension using shared JsonSerializerOptions
ISystemExecutionContextAccessor / SystemExecutionContextAccessor Ambient context carrier: Set(ctx), Get(), Clear()
IContextResolver / NullContextResolver Default no-op resolver; replace to resolve context from HTTP or messaging headers
ITenantContextPolicy / DefaultTenantContextPolicy Policy for extracting tenant identity from context
MSequentialGuidGenerator Sequential GUID factory; Instance.Create() targets SQL Server by default
MConfigurationExtension.GetOptions<T>() Binds a config section into a new T
MConfigurationExtension.GetConfigHelper() Reads a config value, decrypting it if EnableEncryption is set
MConfigurationExtension.GetCryptConfigValue() Low-level encrypted value reader
MPaginationConfig Pagination settings model bound from PaginationConfigs section
MPaginationExtensions.AddPaginationConfigs<TPaging>() Public extension for registering custom pagination config types
MStringExtension.NormalizeString() Accent-strips and lowercases a string (useful for search normalization)

Samples

  • Quickstart.Core — Minimal ASP.NET Core API demonstrating IMDateTimeService, IMJsonSerializeService, and ISystemExecutionContextAccessor via three controller endpoints.

Compatibility

  • Target framework: net8.0
  • Requires: Microsoft.AspNetCore.App framework reference
  • License: Apache-2.0 (OSS)
  • Muonroi.Core.Abstractions — Contracts (IMDateTimeService, IMJsonSerializeService, ISystemExecutionContextAccessor, IClockProvider, IGuidGenerator, guards, and common models) that this package implements. Depend on Abstractions alone when authoring library code that must not take a runtime dependency.
  • Muonroi.Logging — Muonroi structured logging provider wired in by AddCoreServices.
  • Muonroi.AspNetCore — HTTP middleware and ASP.NET Core extensions that build on the execution context registered here.

License

Apache-2.0. See LICENSE-APACHE at the repository root.

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.

NuGet packages (15)

Showing the top 5 NuGet packages that depend on Muonroi.Core:

Package Downloads
Muonroi.Mediator

Mediator pattern implementation for Muonroi: command/query dispatching, pipeline behaviors, and validation integration.

Muonroi.Data.EntityFrameworkCore

Entity Framework Core infrastructure for Muonroi: MDbContext with audit, soft-delete, multi-tenant filters, and repository base.

Muonroi.Messaging.Abstractions

Message bus contracts: IIntegrationEvent, IEventHandler, and message envelope types for Muonroi messaging integrations.

Muonroi.Auth

JWT authentication infrastructure: token validation, DPoP binding, claim extraction, and Muonroi auth middleware.

Muonroi.Governance

OSS license governance implementation: basic license verification, capability resolution, and no-op implementations for free-tier usage.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0-alpha.16 203 6/22/2026
1.0.0-alpha.15 217 5/31/2026
1.0.0-alpha.14 205 5/15/2026
1.0.0-alpha.13 172 5/2/2026
1.0.0-alpha.12 110 4/2/2026
1.0.0-alpha.11 161 4/2/2026
1.0.0-alpha.9 93 3/30/2026
1.0.0-alpha.8 329 3/28/2026
1.0.0-alpha.7 91 3/27/2026
1.0.0-alpha.5 77 3/27/2026
1.0.0-alpha.4 75 3/27/2026
1.0.0-alpha.3 81 3/27/2026
1.0.0-alpha.2 78 3/26/2026
1.0.0-alpha.1 116 3/8/2026