Service needs buildLink

App needs to let users send an invitation email to other potential
users. The invitations contain a special link that gets you access to
the registration pg. When you submit an email adr to invite, the
handler method needs to save a record in the Invitations table, and
actually send the email. Both those actions seem to me like they
belong at the model-level, since they're so tightly related -- the db
record is what makes the email invite valid.

So, I thought RegisterService.createInvitation should do both. The
contents of the email are completely static except for the actual link
and the name of the person who sent it, so I built a getEmailBody
method in RegisterService.

However, buildLink, which is how the link in the email should be
built, isn't available to services. I wondered if that meant I was
thinking about this wrong, that the email was really a view, where
buildLink would be available. Still, I can't get past how coupled the
email and the db record are. It shouldn't be the handler that gets a
random key and coordinates the email/db thing, it's all one
model-level action. The content of the email seems like a business
rule, and the view layer is different, it's what the user sees after
they submit.

So how can I access buildLink from a service? What other strategies
should I think about to get past this?

Dave

  1. One option is to inject the coldbox request service into your service like:
  1. Then, in your service you can do something like:

instance.requestService.getContext().buildLink()

  • Gabriel

You can pass the Event object to your service.

Then, you have full access to the RequestCollection and Event.buildLink().

Build link is also a method that uses the “sesBaseURL” or index.cfm template. So if you are using ses, it is very easy to build links because you can just inject that setting

and that’s it, use that.

Luis F. Majano
President
Ortus Solutions, Corp

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Thanks for the ideas guys. Here's what I've ended up with in my
handler so far, splitting out the creation of the invitation key infos
from the actual save and send email call: