๐ WAYPOINT LESSON
Checkpoint โ The Wired Engine
โญโญ intermediateโณ 35 min read๐ Lesson 155 of 265
The capstone's final composition: async JSON persistence behind the store interface, load-boot round-trips, and the DI-shaped wiring that hands the service its collaborators.
The gate (mini-build)
Two seams, final form:
- JSON snapshot round-trip โ implement
Solution.Snapshot(System.Collections.Generic.IReadOnlyList<TaskItem> tasks)returning the JSON string for the list (camelCase property names, enums as strings), andSolution.Load(string json)parsing it back with case-insensitive names. Round-trip must preserve id, projectId, title, assigneeId, priority, and status exactly (order included). - Wiring โ implement
Solution.BuildEngine(FakeStore store)that constructs the engine as the composition root would: aServiceover the given store, returning it. TheService(nested inSolution, constructor takesFakeStore) must exposeSystem.Threading.Tasks.Task<int> CreateAsync(int projectId, string title, Priority priority, System.Threading.CancellationToken ct)โ validates the title (DomainGuard.ValidTitle), allocates ids 1,2,3โฆ, stores via the store'sTask PutAsync(TaskItem item, System.Threading.CancellationToken ct), respects cancellation (a cancelled caller getsSystem.OperationCanceledExceptionand nothing is stored), surfaces store failures to its caller, and returns the new id.FakeStore(provided) records puts and can be pre-seeded withSeed(TaskItem); itsTask PutAsynccompletes synchronously (a fake), andPutslists what arrived.
public static class Solution
{
public static string Snapshot(System.Collections.Generic.IReadOnlyList<TaskItem> tasks);
public static TaskItem[] Load(string json);
public sealed class Service
{
public Service(FakeStore store);
public System.Threading.Tasks.Task<int> CreateAsync(int projectId, string title, Priority priority, System.Threading.CancellationToken ct);
}
public static Service BuildEngine(FakeStore store);
}
// provided: TaskItem, Priority, Status, DomainGuard.ValidTitle,
// FakeStore { Task PutAsync(TaskItem, CancellationToken); List<TaskItem> Puts; void Seed(TaskItem); }