wblakemd said the following on 01/26/2011 07:40 AM:
> This is a case where I am not sure why the data needs to pass through
> the service layer.  I understand that the listener shouldn't have any
> business logic but should be used to control the application flow.
A service layer is extremely important especially if you want to start
leveraging other "view" technologies (AJAX, REST, etc.) that all will
utilize your service layer.  I wouldn't worry if a few of your methods
in your service layer merely act as a "facade" to your DAO/Gateway
layer.  Your service layer will act as "bumpers" for future changes in
your application especially if you make under lying changes to your
infrastructure.

It probably seems like overkill and that is why you are asking the
question.  However it's extremely common for services objects to talk to
each other.  Be wary of what you put in your listeners, I've found that
it's easy for newer application architects to stick a lot of business
logic in listeners.  It's tempting to make listeners into service
objects.  But, trust me -- clearly separating concerns -- you'll thank
yourself later if you want to leverage things like Flex or build a REST
API, etc.

Listeners should only perform Mach-II specific logic and make decisions
on the "flow" of your applications.  Here's an example of a listener
that is lightweight:

<cfcomponent
    displayname="showroomListener"
    extends="MachII.framework.Listener"
    depends="showroomService,udfs,sessionFacade"
    output="false">

    <!---
    INITIALIZATION / CONFIGURATION
    --->
    <cffunction name="configure" access="public" returntype="void"
output="false"
        hint="Configures the listener.">
    </cffunction>

    <!---
    PUBLIC FUNCTIONS
    --->
    <cffunction name="save" access="public" returntype="void" output="false"
        hint="Saves a showroom.">
        <cfargument name="event" type="MachII.framework.Event"
required="true" />

        <cfset var showroom = arguments.event.getArg("showroomBean") />
        <cfset var errors =
getShowroomService().validateAndSave(showroom) />

        <cfif NOT StructCount(errors)>
            <cfset arguments.event.setArg("message", "The showroom has
been saved.") />
            <cfset
getAppManager().getCacheManager().clearCachesByAlias("showrooms",
arguments.event, "") />
            <cfset redirectEvent("pass", "", true) />
        <cfelse>
            <cfset arguments.event.setArg("errors", errors) />
            <cfset redirectEvent("fail", "", true) />
        </cfif>
    </cffunction>

    <cffunction name="read" access="public" returntype="void" output="false"
        hint="Read a showroom.">
        <cfargument name="event" type="MachII.framework.Event"
required="true" />

        <cfset var showroomId =
arguments.event.getArg("showroomId").trim() />
        <cfset var statuscode = "active" />
        <cfset var showroom = "" />

        <cfif getSessionFacade().isLoggedIn()>
            <cfset statuscode = "all" />
        </cfif>

        <cfif IsNumeric(showroomId)>
            <cfset showroom = getShowroomService().read(showroomId,
statuscode) />
           
            <cfreturn showroom />
        <cfelse>
            <cfset redirectEvent("aboutUs.showrooms") />
        </cfif>
    </cffunction>

</cfcomponent>

As you can see, only event decision, basic validation and simple
event-arg translation is done in the listener.  More complex things like
validation of data collected from a form is done in the service layer.

HTH,
.Peter

-- 
You received this message because you are subscribed to Mach-II for CFML list.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/mach-ii-for-coldfusion?hl=en

SVN: http://svn.mach-ii.com/machii/
Wiki / Documentation / Tickets: http://trac.mach-ii.com/machii/

Reply via email to