Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Checkpoint โ€” The User Directory with a Repository

โญโญ intermediateโณ 25 min read๐Ÿ“ Lesson 134 of 265

Compose the layer: parameterized repository over the engine, transactional registration, fake-backed service tests.

The gate (mini-build)

A user directory service over the in-memory engine:

  1. IUserRepository โ€” Register(string name), FindByName(string name) (returns User?), Count().
  2. SqlUserRepository(CjDb db) : IUserRepository โ€” every SQL parameterized; Register wraps a uniqueness pre-check and the insert in ONE transaction (begin โ†’ check โ†’ insert โ†’ commit) and returns "ok" or "duplicate".
  3. Map(row) โ†’ User(Name, Balance) โ€” balance defaults to 0 when the column is null.
  4. UserService(IUserRepository) โ€” Invite(string name) returns "invited:<name>" on success, "exists:<name>" when the name is taken (Module 11: the service knows only the interface).

User: record User(string Name, decimal Balance).