ConsoleMVC.Framework
1.9.0
See the version list below for details.
dotnet add package ConsoleMVC.Framework --version 1.9.0
NuGet\Install-Package ConsoleMVC.Framework -Version 1.9.0
<PackageReference Include="ConsoleMVC.Framework" Version="1.9.0" />
<PackageVersion Include="ConsoleMVC.Framework" Version="1.9.0" />
<PackageReference Include="ConsoleMVC.Framework" />
paket add ConsoleMVC.Framework --version 1.9.0
#r "nuget: ConsoleMVC.Framework, 1.9.0"
#:package ConsoleMVC.Framework@1.9.0
#addin nuget:?package=ConsoleMVC.Framework&version=1.9.0
#tool nuget:?package=ConsoleMVC.Framework&version=1.9.0
ConsoleMVC
An MVC framework for console applications, inspired by ASP.NET Core MVC.
ConsoleMVC brings the familiar Controller-ViewModel pattern to console apps, with convention-based routing, reflection-based auto-discovery, and Razor-like .cvw view templates powered by a C# source generator.
Quick Start
# Install the template
dotnet new install ConsoleMVC.Template
# Create a new project
dotnet new consolemvc -n MyApp
cd MyApp
dotnet run
How It Works
Program.cs: familiar ASP.NET-style builder:
var builder = MvcApplication.CreateBuilder(args);
builder.Services.AddSingleton<IGreetingService, GreetingService>(); // optional
using var app = builder.Build();
await app.RunAsync();
Controllers: inherit from Controller, return ActionResult:
public class HomeController : Controller
{
public ActionResult Index()
{
var model = new HomeViewModel { Title = "Hello!" };
return View(model);
}
}
Views: .cvw files with an @model directive and C-View Markup, no class boilerplate:
@model MyApp.Models.HomeViewModel
<box title="@Model.Title" border="rounded" color="cyan">
<text>@Model.Message</text>
</box>
<input name="Name" label="Your name: " required />
<menu>
<option key="1" nav="Greet/Result" post>Greet me</option>
<option key="q" quit>Exit</option>
</menu>
Models: simple DTOs:
public class HomeViewModel
{
public string Title { get; set; } = "";
}
Features
- Convention-based routing: Controllers and Views are auto-discovered via reflection and namespace conventions
- Razor-like view engine:
.cvwfiles are compiled intoConsoleView<TModel>classes at build time by a source generator - No boilerplate: Views are plain C# code with an
@modeldirective, no class inheritance required - C-View Markup:
<box>,<text>,<separator>,<br>and<table>elements with colours, borders, alignment and word wrapping, plus@expressions and@if/@foreach; validated at compile time with errors pointing at the.cvwfile - Layout and themes:
<columns>(stacking on narrow terminals),min-width/max-width, and theme classes withclass="title" - Partial views: reusable markup in
Views/Shared/{Name}.cvw, rendered with<partial name="Header" model="@Model.Title" />and checked at build time - Declarative input and navigation:
<input>fields (required, default, masked) collect aForm, and<menu>reads the choice and navigates - Secure output: model values are sanitised so they cannot inject terminal escape sequences
- Reusable rendering engine: the
ConsoleMVC.Renderingnamespace can draw elements in any console app - Familiar API:
View(),RedirectToAction(),ViewData, all the patterns you know from ASP.NET Core MVC - Navigation: Views return
NavigationResultto control app flow (NavigationResult.To(),NavigationResult.Quit()) - Validation: posted forms are checked with DataAnnotations (
[Required],[Range],[EmailAddress], …) before the action runs; useModelState.IsValid,View("Form", model)and<errors />as in ASP.NET Core MVC - Dependency injection:
builder.Services(Microsoft.Extensions.DependencyInjection); constructor injection into controllers,@inject Type Namein views, one scope per screen - Async actions and middleware:
Task<ActionResult>actions,RunAsync(token), andapp.Use(...)/UseMiddleware<T>()around every action - Live reload:
dotnet watchapplies.cvwand C# edits to the running app from the next screen; new pages are discovered automatically - Form data posting: Views collect user input via
Console.ReadLine()and post it to controller actions usingNavigationResult.To("Controller", "Action", formData). The framework automatically binds the data to action method parameters, either as individual simple types (int,string, etc.) or as a complex model class with matching property names
IDE Support
For .cvw file recognition, syntax highlighting, and icon support in JetBrains Rider, install the ConsoleMVC CVWSupport plugin:
Documentation
For full documentation and source code, visit the GitHub repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on ConsoleMVC.Framework:
| Package | Downloads |
|---|---|
|
ConsoleMVC.Testing
Test ConsoleMVC applications end to end: run them with scripted lines and keys, capture every screen as plain text, assert on the routes visited, and compare screens with snapshot files. Works with xUnit, NUnit and MSTest. |
GitHub repositories
This package is not used by any popular GitHub repositories.