C# API Reference
Server-side APIs for Minimact components running on ASP.NET Core.
Overview
When you write TSX and transpile it with Babel, the generated C# code uses these APIs. You rarely write C# directly — these docs help you understand what's happening under the hood.
Core APIs
MinimactComponent
Base class for all components. Provides state management, lifecycle hooks, and predictive rendering.
public class Counter : MinimactComponent
{
protected override VNode Render() { ... }
}Key methods:
SetState()— Update state and trigger re-renderOnInitializedAsync()— Async initializationOnStateChanged()— React to state changesRegisterHint()— Predictive rendering hints
StateManager
Manages component state with attribute-based declarations.
[UseState]
private int count = 0;
[State]
private User user = new();Attributes:
[UseState]— Server-managed state (synced to client)[State]— Server-only state[ClientComputed]— Client-computed values
Coming soon
ComponentRegistry
Tracks active component instances and their lifecycles.
registry.RegisterComponent(component);
var component = registry.GetComponent(componentId);Coming soon
MinimactHub
SignalR hub for real-time bidirectional communication.
// In Program.cs
app.MapHub<MinimactHub>("/minimact");Methods:
InvokeComponentMethod()— Call server methods from clientUpdateComponentState()— Sync state changesUpdateDomElementState()— Sync DOM state
Coming soon
Routing APIs
MinimactRouting
File-based routing with automatic route registration.
// In Program.cs
app.MapMinimactPages();How it works:
- Babel generates
routes.jsonfrom/pages/folder MapMinimactPages()reads manifest- Routes automatically registered with ASP.NET Core
Coming soon
Data Structures
VNode
Virtual DOM node representation.
public class VNode
{
public string Type { get; set; }
public Dictionary<string, string>? Props { get; set; }
public VNode[]? Children { get; set; }
}Types:
VElement— HTML elementVText— Text nodeVFragment— Fragment (multiple children)
Coming soon
Patch
DOM update operation from Rust reconciliation engine.
public class Patch
{
public string Type { get; set; }
public List<int> Path { get; set; }
public string? Content { get; set; }
}Patch types:
UpdateText— Update text contentUpdateProp— Update attributeInsertChild— Add new elementRemoveChild— Remove element
Coming soon
Attributes
Component Attributes
Mark generated components for discovery.
[Component("Counter")]
public class Counter : MinimactComponent { }State Attributes
Declare state variables.
[UseState]
private int count = 0;Template Attributes
Mark compile-time templates (generated by Babel).
[LoopTemplate("items", @"{""template"": ""<li>{0}</li>""}")]
public class TodoList : MinimactComponent { }Coming soon
Service Extensions
AddMinimact()
Register Minimact services with dependency injection.
builder.Services.AddMinimact(options =>
{
options.EnableHotReload = true;
options.HotReloadLogging = true;
options.PredictionCacheSize = 1000;
});Options:
EnableHotReload— Enable template-based hot reloadHotReloadLogging— Log template changesPredictionCacheSize— Max predictions to cache
Coming soon
Advanced APIs
RustBridge
Interface to Rust reconciliation engine.
var patches = RustBridge.Reconcile(oldVNode, newVNode);
var prediction = RustBridge.Predict(stateChange, currentVNode);Coming soon
DynamicValueCompiler
Function-based value binding system.
DynamicBindings.RegisterBinding(".price", (state) => {
return state["isPremium"] ? factoryPrice : retailPrice;
});Coming soon
TemplateHotReloadManager
Watch for template changes and send patches to clients.
var manager = new TemplateHotReloadManager(
hubContext,
registry,
logger,
watchPath: "./Generated"
);Coming soon
Configuration
Program.cs Setup
Complete setup example:
using Minimact.AspNetCore;
using Minimact.AspNetCore.Routing;
var builder = WebApplication.CreateBuilder(args);
// Add Minimact services
builder.Services.AddMinimact(options =>
{
options.EnableHotReload = true;
options.HotReloadLogging = true;
});
// Add SignalR
builder.Services.AddSignalR();
var app = builder.Build();
// Serve static files
app.UseStaticFiles();
// Map SignalR hub
app.MapHub<MinimactHub>("/minimact");
// Map file-based routes
app.MapMinimactPages();
app.Run();Type Safety
Minimact provides full type safety from TypeScript to C#:
TypeScript:
interface User {
name: string;
email: string;
}
export function UserCard({ user }: { user: User }) {
return <div>{user.name}</div>;
}Generated C#:
public class User
{
public string Name { get; set; }
public string Email { get; set; }
}
public class UserCard : MinimactComponent
{
[Prop]
public User User { get; set; }
protected override VNode Render()
{
return new VElement("div", null, new VText(User.Name));
}
}Full IntelliSense, compile-time checking, and refactoring support!
Next Steps
- MinimactComponent API — Component base class
- Client Hooks API — TypeScript/React hooks
- Getting Started — Setup guide
- Architecture Overview — How it works
🌵 Write TSX. Get C#. Ship fast. 🌵
