This queues up BUT DOES NOT EXECUTE the service call. Please take a
deeper look at the documentation for the lifecycle which shows that
services execute *after* the controller item.
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)
As an aside on this, I have abandoned the concept of queuing up
service calls completely for FW/1 on Clojure.
FW/1 1.x implicitly called services for you because a lot of (naive)
MVC code I'd seen had a lot of simple controller methods that merely
delegated to service methods. That's why there was the start/end item
method pairs as well. I still believe that was the right choice in
2009.
In FW/1 2.0, the implicit service calls no longer happen (by default)
but the service() call remains for queuing up calls. This is
deliberate to discourage fat controllers with lots of service calls
and manipulation of data.
In Clojure, there are no side effects - so there's no temptation to
write a slew of service calls and assignments in your controller
functions. Consequently, your controller functions are pure functions
of the request context: given rc, return an updated rc containing keys
whose values are the results of function calls into the model. Since
there's no objects in Clojure, there's no separation into "services"
and "domain objects" so there's just The Model (which is code
containing your business logic). Consequently, there's no service()
API.
Nor is there a controller() API method in the Clojure version. There's
no "lifecycle" methods (a la Application.cfc). There's no
"application" scope (because that concept is all about mutable global
variables). Cookies, sessions and "flash" are all handled as keys in
the request context (because that's how the underlying Ring machinery
which handles HTTP request/response works).
Currently, the Clojure version supports before() / after() around
controller item functions to make section-wide operations easy. I plan
to add :before / :after configuration to specify application-wide
functions (you'll simply specify functions for those).
I'll probably back-port some of these simplifications and concepts
back to a future release of FW/1 for CFML (so, yes, there will be
continued development of the CFML version for a long time, don't
worry!).
And as a follow-on from this, the simplification and streamlining is
likely to be the easiest way to a version of FW/1 that doesn't require
you to extend it into Application.cfc - which in turn will make it
_much_ easier to migrate existing applications to FW/1 by allowing
piecemeal migration while the legacy code continues to use
Application.cfm, for example...
Because - as the documentation explains - calling service() causes the
method call to be queued up, not executed.
Look at the documentation:
https://github.com/seancorfield/fw1/wiki/Developing-Applications-Manual
Under "Designing Controllers" it explains the lifecycle of a request
and when various things run.
If you have startFoo() / endFoo() controller methods and startFoo()
calls service("main.foo") then the main.cfc:foo() service will be
called before endFoo() is executed.
The point of MVC is to decouple your model (your services) from the
framework so they are reusable. FW/1's approach with services is meant
to encourage that.
Most FW/1 developers switch to explicitly calling services themselves
as their application complexity grows - and managing the model with a
DI framework (such as ColdSpring or DI/1). This is a natural
evolutionary path, IMO.
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
If it's any consolation, if I had the chance to do FW/1 over from
scratch, I would not implement the services convention - I would push
people to a single model/ folder and encourage folks to manage service
calls directly, using a simple DI framework (so I would have made DI/1
a couple of years earlier :)
For the Clojure version, I'm taking advantage of this lesson and not
offering the services convention...
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
If your controller function is empty, you can omit it entirely. Unlike
ColdBox, you don't need a controller function when it doesn't need to
do anything. So, for pure "view" actions, you only need the view
itself (hence the "Simplest Possible FW/1 Application" example has
just views/main/default.html containing Hello World! and no
controller). Hope that makes sense?
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/