Map services with init variables? #3347
mikegrogan
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Is there a recommended way to pass in config settings (e.g. get("datasourcename") ) inside a service?
You can't just call get("datasourcename") inside the service it looks like. If I try to do something in an init function it seems to just find other services and auto wire it up. https://guides.wheels.dev/v4-0-0/digging-deeper/dependency-injection-usage/#auto-wiring-init-parameters
Can I also pass in my own variables to an init? Inside services.cfm I can dump a get variable.
writeDump(var=get("datasourcename"),abort=true,label="");
But I'm not sure if it's possible to pass anything in the service mapping
local.di = injector();
local.di.map("emailService").to("app.lib.emailService").asSingleton();
I see wirebox has something like initWith that might be the closest thing to what I'm thinking.
initwith: https://wirebox.ortusbooks.com/configuration/mapping-dsl/dependencies-dsl
I'm just exploring. This isn't super urgent. Or maybe it's not even a recommended approach.
As a workaround, I can still call a function inside my service and pass in a get variable. It's just maybe not as clean.
All reactions