Building ColdFusion services with ColdSpring and Reactor, part 3

Submitted by Falken on

Our previous article discussed the top-most tier in the stack, Services, and it is to the next layer, the Managers, that we now turn.

Managers are tasked with implementing the buisness process for a single task, observing any rules such as change logging. They hold all your logic about how to actually do the things the client asked the Service to do i.e. update the database via the Data layer, send a notification and then update something else.

They should call other managers to form a sequence of actions, as well as use the data layer to load and save records. Thus there is a one to one mapping from Service methods to a Managers method, and it is common to use the same method name in both layers.

Manager methods may accept and return complex types such as ColdFusion's Query.
A typical Manager method like createUser will take a transfer object and prehapes call upon the email and LDAP managers to notify of the creation before using the data layer to create a record and finaly log the succesful compleation.

This souds like it would be complex, creating all these managers, but we can make use of ColdSpring, or another dependancy injection framework, to create self contained testable units.

A very simple Manager might look like:

<cfcomponent output="false" extends="coldSpringObject" name="departmentService">
<cffunction name="setReactor" returntype="void" output="false">
<cfset variables.Reactor=arguments[1]>
</cffunction>

<cffunction name="getUsersInDepartment" output="false" access="public">
<cfargument name="dept_code" required="true">
<cfscript>
var gw=variables.Reactor.createGateway("user");
var q=gw.createQuery();
q.getWhere().isEqual("user","usr_dept_code",arguments.dept_code);
q.getOrder().setAsc("user","name");
return gw.getByQuery(q);
</cfscript>
</cffunction>
</cfcomponent>

Previous Part | Next part

Sections

Submitted by Falken on Wed, 05/23/2007 - 09:46

Permalink

There appears to have been some problems registering due to the new spam filter, so Brian Kotek had to comment on his own blog.

You can find my comments there too. 

Tom