Card 06/ 07
All 7 cards
ExerciseDifficulty: Advanced1 min
Assign the Right Scope
Three beans, three jobs. Assign singleton or prototype to each, and say whether wiring it into a singleton would need a scoped proxy.
RideRepository— stateless, talks to the database, shared by everything.PdfReceiptBuilder— accumulates lines of text across several method calls while one receipt is being built, then is discarded.CurrentRideContext— one per web request, injected into a singletonRideAuditorelsewhere in the application.
See the assignments
- Singleton. No mutable per-caller state — the exact case singleton exists for.
- Prototype. It accumulates state across calls for one use and is then thrown away; sharing one across every receipt would replay the singleton-counter bug from earlier in this topic.
- Request-scoped, and yes — a scoped proxy, if anything wires it into a singleton the way
RideAuditordid. Without the proxy, the singleton resolves it once at startup and never again.