Muonroi.Core
1.0.0-alpha.16
dotnet add package Muonroi.Core --version 1.0.0-alpha.16
NuGet\Install-Package Muonroi.Core -Version 1.0.0-alpha.16
<PackageReference Include="Muonroi.Core" Version="1.0.0-alpha.16" />
<PackageVersion Include="Muonroi.Core" Version="1.0.0-alpha.16" />
<PackageReference Include="Muonroi.Core" />
paket add Muonroi.Core --version 1.0.0-alpha.16
#r "nuget: Muonroi.Core, 1.0.0-alpha.16"
#:package Muonroi.Core@1.0.0-alpha.16
#addin nuget:?package=Muonroi.Core&version=1.0.0-alpha.16&prerelease
#tool nuget:?package=Muonroi.Core&version=1.0.0-alpha.16&prerelease
Muonroi.Core
Foundational runtime services — datetime, JSON serialization, execution context, clock providers, sequential GUIDs, and configuration helpers — shared across all Muonroi applications.
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 registration —
AddCoreServices()registers all foundational singletons in one call;AddRedisConfiguration()is available separately if you only need Redis binding. - Testable clock abstraction —
IMDateTimeService(implementation:MDateTimeService) exposesNow(),UtcNow(),Today(),UtcToday(),NowTs(),UtcNowTs()so controllers and services never callDateTime.Nowdirectly. - Pluggable static clock —
Clockstatic class delegates to a swappableIClockProvider. Built-in providers:ClockProviders.Utc,ClockProviders.Local,ClockProviders.Unspecified. - JSON serialization wrapper —
IMJsonSerializeServicewrapsSystem.Text.JsonwithIgnoreCyclesandWhenWritingDefaultoptions.JsonExtensions.Serialize(this object)provides an extension-method shortcut. - Ambient execution context —
ISystemExecutionContextAccessor+ISystemExecutionContextcarry tenant ID, user ID, username, correlation ID, auth token, API key, permissions, and source type without threading them through every method signature. - Sequential GUID generation —
MSequentialGuidGenerator.Instance.Create()produces time-ordered GUIDs suited for SQL Server (sequential at end), Oracle (sequential as binary), MySQL/PostgreSQL (sequential as string). - Configuration helpers —
IConfiguration.GetOptions<T>(section),ConfigureStartupConfig<TConfig>(),ConfigureDictionary<TOptions>(), andGetConfigHelper()/GetCryptConfigValue()for transparent AES decryption whenEnableEncryption: trueis set. - Pagination config binding —
MPaginationConfigis bound fromappsettings.jsonand enforcesDefaultPageIndex ≥ 1andDefaultPageSize ≥ 15automatically. - String utilities —
MStringExtensionexposesNormalizeString()(accent removal, to-lowercase),DecryptConfigurationValue(), and related helpers. - Structured logging — registers Muonroi logging via
AddMuonroiLogging()(fromMuonroi.Logging). - Problem Details — registers
AddProblemDetails()andAddHttpContextAccessor()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, andISystemExecutionContextAccessorvia three controller endpoints.
Compatibility
- Target framework:
net8.0 - Requires:
Microsoft.AspNetCore.Appframework reference - License: Apache-2.0 (OSS)
Related Packages
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 byAddCoreServices.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 | Versions 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. |
-
net8.0
- Muonroi.Core.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.Logging (>= 1.0.0-alpha.16)
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 |