Skip to content

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.

csharp
public class Counter : MinimactComponent
{
    protected override VNode Render() { ... }
}

Key methods:

  • SetState() — Update state and trigger re-render
  • OnInitializedAsync() — Async initialization
  • OnStateChanged() — React to state changes
  • RegisterHint() — Predictive rendering hints

View full API →


StateManager

Manages component state with attribute-based declarations.

csharp
[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.

csharp
registry.RegisterComponent(component);
var component = registry.GetComponent(componentId);

Coming soon


MinimactHub

SignalR hub for real-time bidirectional communication.

csharp
// In Program.cs
app.MapHub<MinimactHub>("/minimact");

Methods:

  • InvokeComponentMethod() — Call server methods from client
  • UpdateComponentState() — Sync state changes
  • UpdateDomElementState() — Sync DOM state

Coming soon


Routing APIs

MinimactRouting

File-based routing with automatic route registration.

csharp
// In Program.cs
app.MapMinimactPages();

How it works:

  1. Babel generates routes.json from /pages/ folder
  2. MapMinimactPages() reads manifest
  3. Routes automatically registered with ASP.NET Core

View routing guide →

Coming soon


Data Structures

VNode

Virtual DOM node representation.

csharp
public class VNode
{
    public string Type { get; set; }
    public Dictionary<string, string>? Props { get; set; }
    public VNode[]? Children { get; set; }
}

Types:

  • VElement — HTML element
  • VText — Text node
  • VFragment — Fragment (multiple children)

Coming soon


Patch

DOM update operation from Rust reconciliation engine.

csharp
public class Patch
{
    public string Type { get; set; }
    public List<int> Path { get; set; }
    public string? Content { get; set; }
}

Patch types:

  • UpdateText — Update text content
  • UpdateProp — Update attribute
  • InsertChild — Add new element
  • RemoveChild — Remove element

Coming soon


Attributes

Component Attributes

Mark generated components for discovery.

csharp
[Component("Counter")]
public class Counter : MinimactComponent { }

State Attributes

Declare state variables.

csharp
[UseState]
private int count = 0;

Template Attributes

Mark compile-time templates (generated by Babel).

csharp
[LoopTemplate("items", @"{""template"": ""<li>{0}</li>""}")]
public class TodoList : MinimactComponent { }

Coming soon


Service Extensions

AddMinimact()

Register Minimact services with dependency injection.

csharp
builder.Services.AddMinimact(options =>
{
    options.EnableHotReload = true;
    options.HotReloadLogging = true;
    options.PredictionCacheSize = 1000;
});

Options:

  • EnableHotReload — Enable template-based hot reload
  • HotReloadLogging — Log template changes
  • PredictionCacheSize — Max predictions to cache

Coming soon


Advanced APIs

RustBridge

Interface to Rust reconciliation engine.

csharp
var patches = RustBridge.Reconcile(oldVNode, newVNode);
var prediction = RustBridge.Predict(stateChange, currentVNode);

Coming soon

DynamicValueCompiler

Function-based value binding system.

csharp
DynamicBindings.RegisterBinding(".price", (state) => {
    return state["isPremium"] ? factoryPrice : retailPrice;
});

Coming soon

TemplateHotReloadManager

Watch for template changes and send patches to clients.

csharp
var manager = new TemplateHotReloadManager(
    hubContext,
    registry,
    logger,
    watchPath: "./Generated"
);

Coming soon


Configuration

Program.cs Setup

Complete setup example:

csharp
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:

tsx
interface User {
  name: string;
  email: string;
}

export function UserCard({ user }: { user: User }) {
  return <div>{user.name}</div>;
}

Generated C#:

csharp
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


🌵 Write TSX. Get C#. Ship fast. 🌵

Released under the MIT License.