Wirebox, is this right?

Hi,

I'm running CF 9.01 and have a ColdBox 3.1 application that uses
modules. I'm trying to learn how to leverage Wirebox and had a
question if my code looks okay.

I'm building a screen where I can edit a user's details. I have a
handler with this code:

<cffunction name="edituser" access="public" returntype="void">
<cfargument name="Event" type="any" required="yes" />
<cfset var rc = event.getCollection() />
<cfset var injector =
createObject("component","coldbox.system.ioc.Injector").init() />
<cfset var populator = injector.getObjectPopulator() />
  <cfset var objUserBean =
injector.getInstance("modules.moduleName.model.UserBean").init() />
  <cfset Event.setValue('qUser',
instance.UserManager.getUser( rc.user_Id ) ) />
  <cfset objUserBean = populator.populateFromQuery( objUserBean,
rc.qUser ) />
  <cfset Event.setView(name="usermanager/
vwEditUser",layout='Layout.ModuleName') />
</cffunction>

I feel like that is a lot of code to get my bean populated. Am I
doing to much here? What can I do to shorten this code.

Any help appreciated

-West

<cfset rc.qUser = wirebox
.getObjectPopulator
.populateFromQuery( getModel(“UserBean”), instance.userManager.getUser( rc.user_id ) )>

<cfset Event.setView(name=“usermanager/vwEditUser”,layout=‘Layout.ModuleName’) />

First of all, you don’t need to create wirebox if you are using ColdBox already. ColdBox does it for you and manages it for you. All your handlers have wirebox already wired in so you can talk to it. Refer to http://wiki.coldbox.org/wiki/ColdBox.cfm#Major_Classes

Also, by convention all your modules ‘model’ folders are added to the scan locations so you can just say: getModel(“UserBean”).

Luis F. Majano
President
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Thanks a lot Luis. Definitely helps clear things up a bit for me as
I'm learning Wirebox

West