Muonroi.AspNetCore.RuleEngine 1.0.0-alpha.16

This is a prerelease version of Muonroi.AspNetCore.RuleEngine.
dotnet add package Muonroi.AspNetCore.RuleEngine --version 1.0.0-alpha.16
                    
NuGet\Install-Package Muonroi.AspNetCore.RuleEngine -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.AspNetCore.RuleEngine" 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.AspNetCore.RuleEngine" Version="1.0.0-alpha.16" />
                    
Directory.Packages.props
<PackageReference Include="Muonroi.AspNetCore.RuleEngine" />
                    
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.AspNetCore.RuleEngine --version 1.0.0-alpha.16
                    
#r "nuget: Muonroi.AspNetCore.RuleEngine, 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.AspNetCore.RuleEngine@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.AspNetCore.RuleEngine&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Muonroi.AspNetCore.RuleEngine&version=1.0.0-alpha.16&prerelease
                    
Install as a Cake Tool

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.

NuGet License: Apache 2.0

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: AddRuleEngineStore calls EnsureFeatureOrThrow(Premium.RuleEngine) at startup. A license that includes the RuleEngine premium 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 setupAddRuleEngineInfrastructure registers the rule store, both change-management stores, and all MVC generic controller plumbing.
  • Auto CRUDMGenericController<TEntity, TDbContext> generates GET /api/v{version}/[controller], GET /{id}, POST, PUT/{id}, and DELETE/{id} for every non-abstract MEntity subclass discovered in the provided assemblies.
  • Business rule hooks — rules execute at BeforeRule and AfterRule hook 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, and DeletedUserId; records are never physically removed.
  • Multi-tenant isolation — for entities implementing ITenantScoped, queries and writes are automatically filtered to the current tenant (requires MultiTenantConfigs:Enabled = true and 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 managementIRuleChangeStore tracks per-tenant, per-endpoint rule ordering with full history and rollback. IRuleChangeProposalStore supports a propose → approve/reject workflow.
  • OpenTelemetryUiEngineTelemetryDescriptor exports OTLP metrics via the registered OpenTelemetry.Exporter.OpenTelemetryProtocol dependency.

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 via IRuleChangeStore, and generic controller auto-discovery.

Compatibility

  • Target framework: net8.0
  • License: Apache-2.0 (OSS) — runtime rule orchestration requires a Premium.RuleEngine license at startup

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 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 (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