[framework-one] Framework-One Controller and ColdSpring

117 views
Skip to first unread message

Robert

unread,
May 17, 2010, 6:01:48 PM5/17/10
to framework-one
Need to know the best practice for accessing ColdSpring services
within the Framework-One controller. This currently works but does
not seem quite right. Is there a better way to obtain access to your
ColdSpring service layer within the controller?

Application.cfc
<cfset bf =
createObject('component','coldspring.beans.DefaultXmlBeanFactory').init()/
>
<cfset bf.loadBeans(expandPath('/expertportal/questions/config/
ColdSpring.xml'))/>
<cfset setBeanFactory(bf)/>

ColdSpring.xml
<bean id="Question" class="org.app.model.questions.Question"
singleton="false"/>
<bean id="QuestionDAO" parent="parentDAO"
class="org.app.db.questions.QuestionDAO" singleton="true"/>
<bean id="QuestionGateway" parent="parentGateway"
class="org.app.db.questions.QuestionGateway" singleton="true"/>

<bean id="QuestionService" class="org.app.service.questions.Question"
singleton="true">
<property name="DAO">
<ref bean="QuestionDAO"/>
</property>
<property name="Gateway">
<ref bean="QuestionGateway"/>
</property>
</bean>

question.cfc [controller]
<cffunction name="init" access="public" returntype="void"
output="false">
<cfargument name="fw" type="any" required="true"/>
<cfset variables.fw = arguments.fw/>
</cffunction>

<cffunction name="disciplines" access="public" returntype="void"
output="false">
<cfargument name="rc" type="struct" required="true"/>
<cfset rc.test =
variables.fw.getBeanFactory().getBean('QuestionService').getQuestionDisciplines()/
>
</cffunction>

As you can see I am passing the framework into the init method and
then accessing my service using getBeanFactory().getBean() and setting
the results, a query, to the request context.

Do you fellows see a better way?

--
You received this message because you are subscribed to the Google Groups "framework-one" group.
To post to this group, send email to framew...@googlegroups.com.
To unsubscribe from this group, send email to framework-on...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/framework-one?hl=en.

Sean Corfield

unread,
May 17, 2010, 8:19:51 PM5/17/10
to framew...@googlegroups.com
On Mon, May 17, 2010 at 3:01 PM, Robert <rcap...@gmail.com> wrote:
> variables.fw.getBeanFactory().getBean('QuestionService').getQuestionDisciplines()/
...
> As you can see I am passing the framework into the init method and
> then accessing my service using getBeanFactory().getBean() and setting
> the results, a query, to the request context.
>
> Do you fellows see a better way?

Sure, add this function to your controller:

function setQuestionService( questionService ) {
variables.questionService = questionService;
}

then you can just say:

<cfset rc.test = variables.questionService.getQuestionDisciplines() />

FW/1 will autowire it for you...
--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

Robert

unread,
May 17, 2010, 9:50:42 PM5/17/10
to framework-one
Thanks. Adding the one method works perfect.

On May 17, 7:19 pm, Sean Corfield <seancorfi...@gmail.com> wrote:
> On Mon, May 17, 2010 at 3:01 PM, Robert <rcapp...@gmail.com> wrote:
> > variables.fw.getBeanFactory().getBean('QuestionService').getQuestionDisciplines()/
> ...
> > As you can see I am passing the framework into the init method and
> > then accessing my service using getBeanFactory().getBean() and setting
> > the results, a query, to the request context.
>
> > Do you fellows see a better way?
>
> Sure, add this function to your controller:
>
> function setQuestionService( questionService ) {
>     variables.questionService = questionService;
>
> }
>
> then you can just say:
>
> <cfset rc.test = variables.questionService.getQuestionDisciplines() />
>
> FW/1 will autowire it for you...
> --
> Sean A Corfield -- (904) 302-SEAN
> Railo Technologies, Inc. --http://getrailo.com/
> An Architect's View --http://corfield.org/

Dutch Rapley

unread,
May 18, 2010, 4:07:06 PM5/18/10
to framework-one
For service objects that are managed by ColdSpring, you can also use
fw.service()

For example, your service is called QuestionService, you would call it
like this:

<cffunction name="disciplines" access="public" returntype="void"
output="false">
<cfargument name="rc" type="struct" required="true"/>
<cfset fw.service("question.getQuestionDisciplines", "test")/>
</cffunction>

Notice that I left "Service" off the end of "question," as FW/1 will
handle the lookup. Anything in the rc will be copied over to and will
be available within the services argument scope. For example, if you
have rc.firstName in the controller, you could access it in the
service method as arguments.firstName, or simply just firstName.

fw.service() only works for beans in the bean factory that end with
"Service." All other beans you would want to access in your controller
would have to be wired in per Sean's example.

-Dutch

Sean Corfield

unread,
May 18, 2010, 9:35:17 PM5/18/10
to framew...@googlegroups.com
*raises eyebrows*

Hmm, I hadn't thought of using the service() queue API to implicitly
invoke managed services like that... I'm really not sure what I think
about that... It sort of smells funny to me!

The convention is that if you ask for a service called 'foo', FW/1
will look for 'fooService' as a bean in the factory (if you've told it
about a factory) and, failing that (or if you didn't tell it about a
factory), it will look for services/foo.cfc (and instantiate and cache
it for you).

I guess I tend to think if you're managing your services with a
factory, you're probably autowiring them into your controllers and
calling them explicitly. Hmm, well, I guess there's nothing actually
wrong with leveraging the service queue and the conventions like that.
I guess you never know how people will use your software :)

Having written that down, I can see why a Conventions page on the wiki
might be useful since I hadn't thought about that when I answered Mike
Henke earlier. Sigh.

On Tue, May 18, 2010 at 1:07 PM, Dutch Rapley <dutch....@gmail.com> wrote:
> For service objects that are managed by ColdSpring, you can also use
> fw.service()
>
> For example, your service is called QuestionService, you would call it
> like this:
>
> <cffunction name="disciplines" access="public" returntype="void"
> output="false">
>        <cfargument name="rc" type="struct" required="true"/>
>        <cfset fw.service("question.getQuestionDisciplines", "test")/>
> </cffunction>
>
> Notice that I left "Service" off the end of "question," as FW/1 will
> handle the lookup. Anything in the rc will be copied over to and will
> be available within the services argument scope. For example, if you
> have rc.firstName in the controller, you could access it in the
> service method as arguments.firstName, or simply just firstName.
>
> fw.service() only works for beans in the bean factory that end with
> "Service." All other beans you would want to access in your controller
> would have to be wired in per Sean's example.
>
> -Dutch

Reply all
Reply to author
Forward
0 new messages