Minimact.AspNetCore
0.1.4
See the version list below for details.
dotnet add package Minimact.AspNetCore --version 0.1.4
NuGet\Install-Package Minimact.AspNetCore -Version 0.1.4
<PackageReference Include="Minimact.AspNetCore" Version="0.1.4" />
<PackageVersion Include="Minimact.AspNetCore" Version="0.1.4" />
<PackageReference Include="Minimact.AspNetCore" />
paket add Minimact.AspNetCore --version 0.1.4
#r "nuget: Minimact.AspNetCore, 0.1.4"
#:package Minimact.AspNetCore@0.1.4
#addin nuget:?package=Minimact.AspNetCore&version=0.1.4
#tool nuget:?package=Minimact.AspNetCore&version=0.1.4
Minimact C# Runtime
ASP.NET Core runtime for the Minimact framework - a server-side React-like framework with Rust-powered reconciliation.
Architecture
┌─────────────────────────────────────────────────────────────┐
│ Minimact Runtime │
│ │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ MinimactComponent │ │ ComponentRegistry│ │
│ │ (Base Class) │ │ (Singleton) │ │
│ └────────┬─────────┘ └──────────────────┘ │
│ │ │
│ ┌────────▼─────────┐ ┌──────────────────┐ │
│ │ StateManager │ │ RustBridge │ │
│ │ ([State] attrs) │ │ (FFI to Rust) │ │
│ └──────────────────┘ └────────┬─────────┘ │
│ │ │
│ ┌──────────────────┐ ┌────────▼─────────┐ │
│ │ MinimactHub │ │ minimact.dll │ │
│ │ (SignalR) │ │ (Rust Engine) │ │
│ └──────────────────┘ └──────────────────┘ │
└─────────────────────────────────────────────────────────────┘
Project Structure
Minimact.AspNetCore/
├── Core/
│ ├── VNode.cs # Virtual DOM types
│ ├── MinimactComponent.cs # Base component class
│ ├── StateAttribute.cs # [State] attribute
│ ├── StateManager.cs # State synchronization
│ ├── RustBridge.cs # FFI to Rust engine
│ └── ComponentRegistry.cs # Component instance registry
├── SignalR/
│ └── MinimactHub.cs # SignalR hub for real-time updates
├── Extensions/
│ └── MinimactServiceExtensions.cs # ASP.NET Core integration
└── Examples/
├── Counter.cs # Simple counter example
└── TodoList.cs # Todo list with state management
Key Components
VNode Types (VNode.cs)
Virtual DOM representation matching Rust implementation:
VNode- Abstract base classVElement- HTML elements (<div>,<button>, etc.)VText- Text nodes with HTML encodingDivRawHtml- Raw HTML for markdown renderingFragment- React.Fragment-like wrapper
var node = new VElement("div", new VNode[]
{
new VElement("h1", "Hello World"),
new VText("Some text content")
});
string html = node.ToHtml();
// Output: <div><h1>Hello World</h1>Some text content</div>
MinimactComponent (MinimactComponent.cs)
Base class for all components with:
- State management via
SetState()andGetState() - Lifecycle hooks (
OnInitializedAsync,OnStateChanged, etc.) - Rendering via abstract
Render()method - SignalR integration for real-time patches
public class MyComponent : MinimactComponent
{
[State]
private int count = 0;
protected override VNode Render()
{
return new VElement("div", $"Count: {count}");
}
private void Increment()
{
count++;
SetState(nameof(count), count);
}
}
StateManager (StateManager.cs)
Syncs [State] decorated fields/properties with internal state dictionary using reflection:
InitializeState()- Read initial values from fieldsSyncStateToMembers()- Update fields after state changesSyncMembersToState()- Capture field changes before render
RustBridge (RustBridge.cs)
P/Invoke wrapper for Rust reconciliation engine:
// Compute patches
var patches = RustBridge.Reconcile(oldVNode, newVNode);
// Predictor for learning patterns
using var predictor = new RustBridge.Predictor();
predictor.Learn(stateChange, oldTree, newTree);
var prediction = predictor.Predict(stateChange, currentTree);
MinimactHub (MinimactHub.cs)
SignalR hub for client communication:
RegisterComponent()- Connect component to clientInvokeComponentMethod()- Handle client events (clicks, etc.)UpdateClientState()- SyncuseClientStatevalues- Auto-cleanup on disconnect
ComponentRegistry (ComponentRegistry.cs)
Thread-safe singleton registry:
registry.RegisterComponent(component);
var component = registry.GetComponent(componentId);
registry.UnregisterComponent(componentId);
Usage
1. Add to ASP.NET Core app
// Program.cs
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddMinimact(options =>
{
options.EnablePrediction = true;
options.EnableDebugLogging = false;
});
var app = builder.Build();
app.UseMinimact();
app.Run();
2. Create a component
public class Counter : MinimactComponent
{
[State]
private int count = 0;
public override Task OnInitializedAsync()
{
StateManager.InitializeState(this);
return Task.CompletedTask;
}
protected override VNode Render()
{
StateManager.SyncMembersToState(this);
return new VElement("div", new VNode[]
{
new VElement("h1", $"Count: {count}"),
new VElement("button", new Dictionary<string, string>
{
["onclick"] = nameof(Increment)
}, "Increment")
});
}
private void Increment()
{
count++;
SetState(nameof(count), count);
}
}
3. Render component in controller
public class HomeController : Controller
{
private readonly ComponentRegistry _registry;
public HomeController(ComponentRegistry registry)
{
_registry = registry;
}
public async Task<IActionResult> Index()
{
var counter = new Counter();
_registry.RegisterComponent(counter);
var html = (await counter.InitializeAndRenderAsync()).ToHtml();
ViewBag.ComponentId = counter.ComponentId;
ViewBag.Html = html;
return View();
}
}
Features
✅ Virtual DOM - React-like VNode tree structure
✅ State Management - [State] attributes with auto-sync
✅ Rust Reconciliation - High-performance diffing via FFI
✅ SignalR Patches - Real-time DOM updates
✅ Predictive Rendering - ML-based patch prediction
✅ Lifecycle Hooks - Initialize, state changes, mount/unmount
✅ Component Registry - Global instance management
✅ Type Safety - Full C# type checking
Next Steps
- Build Rust library - Compile
minimact.dllfrom Rust source - Client runtime - Create
minimact.jsfor DOM patching - Babel integration - Connect TSX transformer to C# codegen
- Hybrid rendering - Implement
useClientStatezones - Testing - Unit tests for all components
Examples
See Examples/ folder:
- Counter.cs - Basic state and event handling
- TodoList.cs - List rendering with keyed reconciliation
Dependencies
- .NET 8.0
- Microsoft.AspNetCore.SignalR.Core 1.1.0
- Markdig 0.37.0 (for
useMarkdown) - Newtonsoft.Json 13.0.3 (for JSON serialization)
- minimact.dll (Rust reconciliation engine)
License
MIT
| 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
- Markdig (>= 0.37.0)
- Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Minimact.AspNetCore:
| Package | Downloads |
|---|---|
|
Minimact.Charts
Server-side charting library for Minimact with zero client bundle overhead. Includes Bar, Line, Pie, and Area charts with Recharts-inspired API. |
|
|
Minimact.Powered
Interactive "Powered by Minimact" badge plugin with smooth slide-out animation. Uses parameterized template patches for instant state transitions. |
GitHub repositories
This package is not used by any popular GitHub repositories.