Muonroi.AspNetCore.RuleEngine
1.0.0-alpha.16
dotnet add package Muonroi.AspNetCore.RuleEngine --version 1.0.0-alpha.16
NuGet\Install-Package Muonroi.AspNetCore.RuleEngine -Version 1.0.0-alpha.16
<PackageReference Include="Muonroi.AspNetCore.RuleEngine" Version="1.0.0-alpha.16" />
<PackageVersion Include="Muonroi.AspNetCore.RuleEngine" Version="1.0.0-alpha.16" />
<PackageReference Include="Muonroi.AspNetCore.RuleEngine" />
paket add Muonroi.AspNetCore.RuleEngine --version 1.0.0-alpha.16
#r "nuget: Muonroi.AspNetCore.RuleEngine, 1.0.0-alpha.16"
#:package Muonroi.AspNetCore.RuleEngine@1.0.0-alpha.16
#addin nuget:?package=Muonroi.AspNetCore.RuleEngine&version=1.0.0-alpha.16&prerelease
#tool nuget:?package=Muonroi.AspNetCore.RuleEngine&version=1.0.0-alpha.16&prerelease
Muonroi.AspNetCore.RuleEngine
ASP.NET Core integration that wires the Muonroi Rule Engine into Auto CRUD controllers, business-rule orchestration, and tenant-scoped rule change management — in a single call.
Muonroi.AspNetCore.RuleEngine bridges Muonroi.RuleEngine.Core / Muonroi.RuleEngine.Runtime with ASP.NET Core. It provides AddRuleEngineInfrastructure, which registers the rule store, change-management stores, and generic controller wiring in one call. MGenericController<TEntity, TDbContext> automatically serves paginated list, get-by-id, create, update, and soft-delete endpoints for every MEntity subclass found in the supplied assemblies, executing business rules before and after each mutation.
License gate:
AddRuleEngineStorecallsEnsureFeatureOrThrow(Premium.RuleEngine)at startup. A license that includes theRuleEnginepremium feature must be present for the application to start.
Installation
dotnet add package Muonroi.AspNetCore.RuleEngine --prerelease
Quick Start
using System.Reflection;
using Muonroi.AspNetCore.Extensions;
WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
// Registers in one call:
// - rule engine store (bound from "RuleStoreConfigs" configuration section)
// - IRuleChangeStore -> InMemoryRuleChangeStore
// - IRuleChangeProposalStore -> InMemoryRuleChangeProposalStore
// - MVC generic controller wiring (GenericControllerRouteConvention +
// GenericControllerFeatureProvider) for MGenericController<TEntity, TDbContext>
builder.Services.AddRuleEngineInfrastructure(
builder.Configuration,
Assembly.GetExecutingAssembly()); // scanned for MEntity subclasses + MDbContext
WebApplication app = builder.Build();
app.MapControllers();
app.Run();
Adding business rules for CRUD
// Register a RuleOrchestrator for ProductEntity with one validation rule and one hook.
builder.Services.AddCrudRules<ProductEntity>(rules =>
{
rules.AddCrudRule<ProductEntity, ProductValidationRule>();
});
builder.Services.AddCrudHook<ProductEntity, AuditHook>();
builder.Services.AddCrudRuleListener<ProductEntity, ProductRuleEventListener>();
ProductValidationRule must implement IRule<CrudContext<ProductEntity>>.
The orchestrator runs matching rules at HookPoint.BeforeRule and HookPoint.AfterRule for each Create/Update/Delete call. If a rule sets context.CancelOperation = true or populates context.ValidationErrors, the controller returns 400 Bad Request with the error message — the database write never occurs.
Features
- Single-call infrastructure setup —
AddRuleEngineInfrastructureregisters the rule store, both change-management stores, and all MVC generic controller plumbing. - Auto CRUD —
MGenericController<TEntity, TDbContext>generatesGET /api/v{version}/[controller],GET /{id},POST,PUT/{id}, andDELETE/{id}for every non-abstractMEntitysubclass discovered in the provided assemblies. - Business rule hooks — rules execute at
BeforeRuleandAfterRulehook points for Create, Update, and Delete operations; returning a failure cancels the operation without touching the database. - Mass-assignment protection — the Update endpoint guards system fields (
EntityId,CreationTime,TenantId, etc.) from being overwritten. - Soft delete with audit trail — Delete sets
IsDeleted,DeletionTime, andDeletedUserId; records are never physically removed. - Multi-tenant isolation — for entities implementing
ITenantScoped, queries and writes are automatically filtered to the current tenant (requiresMultiTenantConfigs:Enabled = trueand a Premium.MultiTenant license). - Permission enforcement — decorating a derived controller with
[GenericCrudPermission]enables RBAC checks backed by role-permission queries with multi-level cache support. - Rule change management —
IRuleChangeStoretracks per-tenant, per-endpoint rule ordering with full history and rollback.IRuleChangeProposalStoresupports a propose → approve/reject workflow. - OpenTelemetry —
UiEngineTelemetryDescriptorexports OTLP metrics via the registeredOpenTelemetry.Exporter.OpenTelemetryProtocoldependency.
Configuration
{
"RuleStoreConfigs": {
// populated by Muonroi.RuleEngine.Runtime's AddRuleEngineStore internals
},
"MultiTenantConfigs": {
"Enabled": false,
"RequireTenantClaimForAuthenticatedUser": true
}
}
The RuleStoreConfigs section is consumed by AddRuleEngineStore (from Muonroi.RuleEngine.Runtime). Refer to that package's documentation for all available keys.
API Reference
| Type | Purpose |
|---|---|
RuleEngineInfrastructureExtensions.AddRuleEngineInfrastructure |
Main entry point — registers store, change stores, and MVC generic controller wiring |
CrudRuleExtensions.AddCrudRules<TEntity> |
Registers a RuleOrchestrator<CrudContext<TEntity>> with rules, hooks, and listeners |
CrudRuleExtensions.AddCrudRule<TEntity, TRule> |
Registers a single IRule<CrudContext<TEntity>> |
CrudRuleExtensions.AddCrudHook<TEntity, THook> |
Registers a IHookHandler<CrudContext<TEntity>> |
CrudRuleExtensions.AddCrudRuleListener<TEntity, TListener> |
Registers an IRuleEventListener<CrudContext<TEntity>> |
MGenericController<TEntity, TDbContext> |
Auto CRUD controller base; override any action to customize behavior |
CrudContext<TEntity> |
Context object passed to rules — holds Entity, OriginalEntity, OperationType, UserId, TenantId, ValidationErrors, CancelOperation, CancellationReason, and Metadata |
CrudOperationType |
Enum: Create, Update, Delete, Read |
IRuleChangeStore |
Per-tenant, per-endpoint rule ordering: GetCurrentAsync, ApplyAsync, RollbackAsync, GetHistoryAsync |
IRuleChangeProposalStore |
Rule change proposal workflow: ProposeAsync, GetAsync, ApproveAsync, RejectAsync, ListPendingAsync |
GenericControllerFeatureProvider |
IApplicationFeatureProvider<ControllerFeature> — discovers MEntity subclasses and registers generic controllers |
GenericControllerRouteConvention |
Strips the Entity suffix from controller names for clean routes |
Samples
- Quickstart.AspNetCore.RuleEngine — end-to-end wiring of
AddRuleEngineInfrastructure, rule change ordering viaIRuleChangeStore, and generic controller auto-discovery.
Compatibility
- Target framework:
net8.0 - License: Apache-2.0 (OSS) — runtime rule orchestration requires a
Premium.RuleEnginelicense at startup
Related Packages
Muonroi.RuleEngine.Abstractions— contracts:IRule<TContext>,RuleResult,FactBag,HookPoint,CrudContextbase typesMuonroi.RuleEngine.Core—RuleOrchestrator<TContext>, fluent builder, workflow runnerMuonroi.RuleEngine.Runtime— persistence-backed rule store, canary rollout, HMAC/RSA signing, hot-reloadMuonroi.AspNetCore— base ASP.NET Core infrastructure (AddInfrastructure,MDbContext, middleware)
License
Apache-2.0. See LICENSE-APACHE for full terms.
The Rule Engine feature (Premium.RuleEngine) is license-gated and requires a valid Muonroi license at application startup.
| 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.AspNetCore (>= 1.0.0-alpha.16)
- Muonroi.Core.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.RuleEngine.Abstractions (>= 1.0.0-alpha.16)
- Muonroi.RuleEngine.Core (>= 1.0.0-alpha.16)
- Muonroi.RuleEngine.Runtime (>= 1.0.0-alpha.16)
- OpenTelemetry.Exporter.OpenTelemetryProtocol (>= 1.15.3)
- Scriban (>= 7.2.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Muonroi.AspNetCore.RuleEngine:
| Package | Downloads |
|---|---|
|
Muonroi.BuildingBlock.All
Metapackage for Muonroi Building Block - Includes all sub-packages for a complete infrastructure setup. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.0.0-alpha.16 | 53 | 6/22/2026 |
| 1.0.0-alpha.15 | 82 | 5/31/2026 |
| 1.0.0-alpha.14 | 81 | 5/15/2026 |
| 1.0.0-alpha.13 | 79 | 5/2/2026 |
| 1.0.0-alpha.12 | 69 | 4/2/2026 |
| 1.0.0-alpha.11 | 125 | 4/2/2026 |
| 1.0.0-alpha.8 | 162 | 3/28/2026 |