Skip to main content

Checkpoint: full container

Challenge on lesson: Checkpoint: The Complete Mini-DI Container

Extend the practice Container (copy it in) with: 1. Everything from before: recursive constructor injection, singleton cache by Class token, cycle detection throwing IllegalStateException("...circular..."). 2. public <T> boolean canResolve(Class<T> type) — true iff resolve(type) would succeed: every constructor parameter type must itself be resolvable (primitive or array parameter types cannot be injected -> false), and there must be no cycle reachable from type. MUST NOT throw for unresolvable types — answer the question. canResolve must never mutate the singleton cache for types it merely inspects. 3. public int constructions on the CONTAINER (public field) — incremented for every constructor invocation the container performs. (Lets tests distinguish real construction from mere inspection.)

Difficulty: advanced

Back to lesson: Checkpoint: The Complete Mini-DI Container