placing model calls in cfc constructor..

Hi there

Was just wondering, whilst im getting my head around model the meantime, is it acceptable to place model calls
in the constructor area of a cfc..

For example...

<cfcomponent name="artists" extends="coldbox.system.eventhandler"
output="false" hint="all artist functions for site" >

   <cfset Artist= createObject('component',"myapp.model.mdl_Artists")>

Then I can call the object in the methods within the cfc? For example

  <cffunction name="home" access="public" returntype="void"
output="false" hint="displays an artists home page, with songs
   <cfargument name="EVENT" type="any">

    <!---Reference to the request collection--->
     <cfset var rc =event.getCollection()>

     <cfset rc.qrygetArt = Artist.getArtistData(rc.name_art)>


Is this acceptable?


Few things, Yes, they are acceptable, but remember that then the Artist will be in the variables scope of the handler, and the handler is persisted by default. Therfore, you will have thread safety issues if that object holds state. If it is a stateless object then that would be fine.

However, by you creating the object, you have less control and more proned to errors when dealing with object dependencies. For example, that artist needs a datasource, etc. I would suggest you either let coldbox manage your model objects via model integration (ioc by coldbox) or use an external ioc framework like coldspring/lightwire.

This will give you more control on your object creations and you can just autowire them into your handlers. I suggest reading the model integration guide.

Ok, thanks I can see what your saying..

I was just looking for an interim solution whilst I figure out the
issues I was having with model injection that I have posted in another

Prob best I sort that out instead