In this example, I’m injecting my postmarkapp.com mail plugin, for sending emails.
But let’s say down the line I want to switch my email provider, back to standard SMTP, or over to Amazon SES, I’d have to go through all my handlers, service etc, changing the references over to the new plugin.
Is there any way for me to alias this plugin? so I can just inject it as ‘MailService’ and have the reference to which plugin I’m using defined in a single location?
Then your "myMailService" plugin could be whatever implementation
you're using at the moment or the generic plugin can extend from the
plugin you want to use. So you'd have the generic plugin extend from
"postbox" and when you want to change to something else, you'd have it
extend from the amazon ses plugin.
then, you could inject=“id:MailService” into your handlers and whatever…
If your MailService implementation ever does change then all you would need to do is map(“MailService”).toDSL(“coldbox:myPlugin:MyAwesomeMailPlugin”) in the binder and all the handlers and services should pick it up.
As far as I know this should work… unless somebody else sees issue with that approach
@Adam - where should I put this config setting? I’ve seen other discussions with similar things, but the wirebox docs seem to talk about it from a non-coldbox perspective is initing the framework yourself.
Can I add a wirebox.cfc in my config folder and have it picked up automatically?
Stick to aliasing at the binder level and combine it with a interface pattern. So you can replace later on an have the same method signatures for true swap capabilities.