Add a feature: the checklist
One page for every option
This page covers every choice of --Persistence, --Auth, --IncludeTests and --Aspire. A label says which options a part is for; the copy in your app's docs/ folder has only yours. ApiHost stands for your app's name.
The steps for adding a feature, in order. The tutorial goes through each one with a worked example, Contacts; the Todo feature shows more patterns (Architecture).
The API
A feature is a folder, src/ApiHost/Features/<Feature>/. Nothing needs registering: Wolverine finds endpoints by their attributes and handlers by their class names.
- With organisations The data: a class that implements
ITenanted, so it belongs to the request's organisation and queries only see that organisation's data. - With accounts, without organisations The data: a class with an
OwnerId, which every query and change checks. - Without accounts The data: a class with a
Guid Id. - Marten, with organisations Storage: Marten creates the table itself; add
opts.Schema.For<T>().MultiTenanted();inData/Marten/MartenPersistence.cs. - Marten, with accounts, without organisations Storage: Marten creates the table itself; index the owner in
Data/Marten/MartenPersistence.cs. - Marten, without accounts Storage: Marten creates the table itself.
- EF Core Storage: a
DbSetinData/EfCore/AppDbContext.cs, then a migration. - Requests: a record for each request body, and a FluentValidation validator for it, which runs before the endpoint.
- With accounts Endpoints: static methods with
[Authorize]and[WolverineGet],[WolverinePost]and the rest. Answer 404, not 403, for something that isn't the caller's, so its existence isn't revealed. - Without accounts Endpoints: static methods with
[WolverineGet],[WolverinePost]and the rest. - Background work: return a message from the endpoint, and handle it in a class whose name ends in
Handler. It's saved with the data (the outbox) and runs even after a restart. - With accounts Live updates: a message with
[MessageIdentity("...")], routed inProgram.cswithopts.PublishMessage<T>().ToSignalR();, and sent to a group (Realtime/RealtimeGroups.cs) withToWebSocketGroup, so only the right people get it. - Without accounts Live updates: a message with
[MessageIdentity("...")], routed inProgram.cswithopts.PublishMessage<T>().ToSignalR();. - With organisations The data's lifetime: handle
OrganisationDeletedto delete the organisation's data, and add it to the organisation's data export (Features/Todos/TodosOrganisationData.cs). - With accounts, without organisations The data's lifetime: handle
AccountDeletedto delete the user's data, and add it to the user's data export (Features/Todos/TodosPersonalData.cs).
The client
- With the API running,
npm run gen:apiinsrc/Clientupdates the API's types. - A folder,
src/Client/src/features/<feature>/, with TanStack Query hooks and the page. Listen for live updates withuseRealtime(lib/realtime.ts). - A route module in
src/Client/src/routes/, which gives the page's title inhandle(withindex: trueonly if search engines should list it, which also pre-renders it). - With accounts Its URL in
src/Client/src/routes.ts, inside therequire-authlayout if it needs a login, and insrc/Client/src/pages.ts(a unit test checks they match). - With accounts A link in
features/account/AccountNavigation.tsx. - Without accounts Its URL in
src/Client/src/routes.tsandsrc/Client/src/pages.ts(a unit test checks they match). - Without accounts A link in
App.tsx.
Tests
- With accounts, with the tests API tests in
tests/ApiHost.Tests: the happy path, validation, and that nobody else can see or change the data. - Without accounts, with the tests API tests in
tests/ApiHost.Tests: the happy path and validation. - A client test next to the page, with the API faked by MSW.
See Testing.