Practice · 2 of 4
Milestone 2 — Task Repository
Implement the in-memory task store behind its interface — ID
allocation included:
``csharp
public sealed class TaskRepo : Solution.ITaskRepo
{
public TaskRepo(); // empty store
public int NextId(); // starts at 1, monotonic
public TaskItem Add(int projectId, string title, Priority priority); // allocates id, Todo, unassigned
public bool TryFind(int id, out TaskItem task);
public bool Update(TaskItem task); // replace by id; false when missing
public System.Collections.Generic.IReadOnlyList<TaskItem> All();
}
public interface ITaskRepo
{
int NextId();
TaskItem Add(int projectId, string title, Priority priority);
bool TryFind(int id, out TaskItem task);
bool Update(TaskItem task);
System.Collections.Generic.IReadOnlyList<TaskItem> All();
}
`
Both types nest inside Solution. Rules:
- IDs start at 1 and increase by one per Add, independent of removal
attempts (there are none — this repo never deletes),
- Add stores the item as given (validation already happened at the
service),
- Update replaces the whole item; unknown ids return false and change
nothing,
- All` returns a snapshot safe to enumerate while the repo keeps changing
(copy, not live view).
Back to lesson: Practice: Capstone Milestones: Domain to Engine