Hey smart cookies!
I am trying to work out the best way of doing something - I've thought of a few options, but they don't feel right.
What I'm trying to achieve is this:
I have a service - "authService" which has properties like "authEndpoint" "authCallback" "authClientId". These properties are injected via constants that are configured (currently) in app.cfc.
I want to re-use "authService" as aliased beans "authTestService" and "authProdService", but for those separate aliases there would be different endpoint/callback/clientId props.
How would I best do this with DI/1 so that I could, in my calling CFC just have a property for "authProdService" / "authTestService" and be able to do something like:
var authService = variables.authProdService;
if (mode == "test") authService = variables.authTestService;
authService.authenticate(username, password);
The current front-runner approach I've thought of would be to actually create the instances when setting up the bean factory, configure them, and use addBean. ie, something like this in setupApplication (FW/1):
var beanFactory = new ioc(..);
var authServiceProd = beanFactory.getBean("authService");
authServiceProd.setAuthEndPoint(...);
.. other props ..
beanFactory.addBean("authServiceProd", authServiceProd);
.. repeat for authServiceTest.
.. or have the defaults point to prod, and just do the above for authServiceTest.
--
M.