Skip to content

Todo Sample

Mike Christensen edited this page Aug 28, 2026 · 1 revision

Todo sample

The Imp Todo sample is a small but complete ASP.NET Core application. It manages an in-memory list of tasks and demonstrates how Imp features fit together without introducing a database, authentication system, or frontend framework.

Run it

git clone https://github.com/KitchenPC/Imp.git
cd Imp
dotnet run --project Samples/TodoApp/TodoApp.csproj

Open the HTTP URL printed by ASP.NET Core. Tasks reset when the process restarts.

Functionality

  • Add a task.
  • Complete or reopen it.
  • Delete tasks and clear completed tasks.
  • Filter all, active, or completed items through ?Filter=....
  • View a task through /todo/{id}.
  • Visit /about for a direct-rendered page.
  • Receive a real 404 status for unknown routes.

Feature map

File What it demonstrates
Program.cs Middleware order, DI registration, namespaces, fallback routing, CDN paths, lifecycle header.
Pages/Default.cs Constructor injection, enum query binding, loops, dynamic output, async postback, antiforgery, validation.
Pages/Todo.cs Dynamic permalink parsing and 404 for a missing record.
Pages/About.cs Direct rendering without an embedded page template.
Pages/NotFound.cs Configured 404 page and status.
PageTemplates/*.htm Embedded page templates and dynamic commands.
Templates/Site.htm Reusable layout and placeholders.
wwwroot/styles/site.css Static assets referenced through Cdn.href.
TodoStore Thread-safe singleton application service.

Why the store is in memory

The sample isolates Imp concepts. TodoStore is a singleton protected by a lock, so it demonstrates shared service lifetime and concurrent safety while remaining easy to run. Replace it with a repository/database service for durable or multi-instance deployment.

Security choices

All state-changing forms use ASP.NET Core antiforgery tokens, validate an action allow-list, parse IDs, and HTML-encode task titles. The sample does not include [SecurePage] because a responsible example would require choosing and explaining a real authentication scheme. See Authentication and secure pages.

Tests

Samples/TodoApp.Tests verifies adding, normalization, toggling, removal, and input limits. The repository build also compiles all embedded resources. For a production application, add HTTP integration tests covering authentication, antiforgery, response status, and rendered output.

Clone this wiki locally