*> What do you mean by try to use another approach?*
Passing the entire rc struct may be desired, but it's a little sloppy as
it doesn't create a very nice API. Consider, the following two methods:
function createUser( props ) {}
function createUser( firstName, lastName, age ) {}
Which of those two methods is better at documenting what data it requires
to execute? (Correct answer: the second!)
As much as I agree with you, the approach he is trying to do is still
feasibly correct as well. There have been times, that if I followed that
approach the arguments would have over 120 arguments. There comes a time
when you have to say, this needs to be better organised.
Now keeping with that, it can still apply for the OP. For example.
function CreateUser(userInfo, userAddresss, userContact) { }
Now although maybe not the best example, but what I am saying is that the
user name, password are passed in one struct while their Address and
mailing address is passed in the second struct and all their preferred
contacts are then passed in the 3rd struct.
As I said maybe not the best example, but any time you want to pass a heap
of data, breaking it down to manageable structs is better than having 120
arguments being passed.
For the OP, what Brad is saying is that you want to break it all down and
segregate the data. You have to think of your services and models as tiers
constructed in black box scenarios, that means the models and services only
care about what they only care about. And passing the entire RC could be
problematic depending what you have in there for that request.
By the way, when I say Tiers, you should be able to remove that tier and
replace it with now code re-factoring in your handlers.
However, having said all that.
The Request Context is kept in memory for every request anyway, now
although I do not condone this as best practice, there has been a time or
two, where I have injected the Request Context Decorator (sorry if that is
not the right one) to then access the required information from either the
RC or PRC. I usually always use the PRC for my apps and leave the RC for
Coldbox and what it does, that means if I need to use the submitted form
data then I inject the decorator and then grab the required fields.
Now that comes with serious caveats, one of which is validation. You still
should use handlers to block any request that the services and models
should not care about. Validation is the same, it should not enter the
service or model unless it passes all that.
If it was me, I would take a step back and say what it is you're trying to
achieve with your handlers, services and models and code them accordingly,
with the view that these services and models should be factored for total
code reuse.
Regards,
Andrew Scott
WebSite: http://www.andyscott.id.au/
Google+: http://plus.google.com/113032480415921517411