Your ColdSpring beans are (most likely) singletons. Thus onApplicationStart is fine.
On Request would run each request, of course, which probably isn't what you want, unless your bean needs to be created on each request. This, of course, would be using ColdSpring to manage transient objects, which normally is not recommended except for low traffic applications. If you are using ColdSpring to manage transient beans, then the beans scope won't work for you because it'll create a Controller scoped singleton. Your original use, in the init() would also create a controller scoped singleton, ( by the way) DW DW Sent from a mobile. Please excuse brevity and typos. -----Original Message----- From: byron <[email protected]> Sender: [email protected] Date: Thu, 6 Jan 2011 15:42:19 To: model-glue<[email protected]> Reply-To: [email protected] Subject: [Model-Glue] Re: Referencing beans scope in an init function of a controller One other question. I tried the init() method and that worked. For the onApplicationStart method, doesn't that only run when the application starts? Would it be better to do onRequestStart? Or does it really matter? OK, more that one question ;) Byron On Jan 6, 4:27 pm, Ezra Parker <[email protected]> wrote: > No problem. > > I'd say it's a matter of preference -- personally, I tend to avoid > defining init() methods in my controllers, and I prefer using the > beans scope to getModelGlue().getBean(), so I'd go with the > onApplicationStart approach instead. > > -- > Ezra > > On Thu, Jan 6, 2011 at 1:14 PM, byron <[email protected]> wrote: > > Thanks Ezra. Will try this out. Any advantage/disadvantage doing one > > vs the other? Or is it a stylistic preference? > > > Byron > > > On Jan 6, 4:06 pm, Ezra Parker <[email protected]> wrote: > >> On Thu, Jan 6, 2011 at 12:33 PM, byron <[email protected]> wrote: > >> > Thanks, Ezra. Yes, I would like to see an example. > > >> Sure. First you'd add the message listener to your controller's XML config: > > >> <controller id="eHopeController" type="controller.eHopeController"> > >> <message-listener message="onApplicationStart" /> > >> </controller> > > >> Then add the corresponding controller function -- here's a minimalist > >> example: > > >> <cffunction name="onApplicationStart" output="false"> > >> <cfargument name="event" /> > > >> <cfset variables.settings = beans.applicationSettings.getConfig() /> > >> </cffunction> > > >> > Would doing something like > >> > getModelGlue().getBean("applicationSettings", true) work also? > > >> Yes, but with a caveat: > > >> I actually should have mentioned this in my first response, but if > >> you're going to define an init() method in your controllers, you need > >> to make sure to call super.init() in order to execute the base > >> controller's constructor, as otherwise getModelGlue() is not going to > >> work either. Here's the modification you would need to make to the > >> init() method you posted: > > >> <cffunction name="init" access="public" returnType="eHopeController" > >> output="false"> > >> <cfargument name="framework" /> > > >> <cfset super.init(framework) /> > > >> <cfset variables.settings = > >> getModelGlue().getBean("applicationSettings").getConfig() /> > > >> <cfreturn this /> > >> </cffunction> > > >> -- > >> Ezra > > > -- > > Model-Glue Sites: > > Home Page:http://www.model-glue.com > > Documentation:http://docs.model-glue.com > > Bug Tracker:http://bugs.model-glue.com > > Blog:http://www.model-glue.com/blog > > > You received this message because you are subscribed to the Google > > Groups "model-glue" group. > > 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/model-glue?hl=en -- Model-Glue Sites: Home Page: http://www.model-glue.com Documentation: http://docs.model-glue.com Bug Tracker: http://bugs.model-glue.com Blog: http://www.model-glue.com/blog You received this message because you are subscribed to the Google Groups "model-glue" group. 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/model-glue?hl=en -- Model-Glue Sites: Home Page: http://www.model-glue.com Documentation: http://docs.model-glue.com Bug Tracker: http://bugs.model-glue.com Blog: http://www.model-glue.com/blog You received this message because you are subscribed to the Google Groups "model-glue" group. 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/model-glue?hl=en
