New on the blog: Dependency Injection in Wheels 4....
# wheels-dev
p
New on the blog: Dependency Injection in Wheels 4.0 — services.cfm, scopes, and auto-wiring. <https://blog.wheels.dev/posts/dependency-injection-services-scopes/> What it covers: • Registering services in
config/services.cfm
with
injector()
+ the fluent
di.map("x").to("...").asSingleton()
chain (and yes — you create that file yourself; the scaffold ships none) • The three lifetimes — transient (the DEFAULT, the one that bites),
.asSingleton()
,
.asRequestScoped()
— and when to reach for each • Resolving anywhere with
service("name")
(it throws
Wheels.DI.ServiceNotFound
, it doesn't return null) • Controller
inject("a, b")
in config() → use as
this.a
in actions, resolved per-request • Constructor auto-wiring:
init()
param names that match registered mappings get filled in for free • Sharp edges: singletons cached by mapping NAME not component path; auto-wiring only fires with empty initArguments;
mapInstance()
vs
map()
in plugins A user-facing how-to — not the wheelsdi internals story (that's the earlier "From WireBox to wheelsdi" post).