Rony sent me some interesting questions today concerning existing code and Model-Glue. He sent two questions. His second question was easier so I'll address that one first:
I also have several variables, objects (such as DAO's, gateways) and structs inside stored in my application scope. How I can integrate this with MG?
Model-Glue makes this rather simple. All controllers (you should have at least one per application) are automatically stored in the Application scope. This may not be 100% obvious as you don't see the Application scope used in your own, but it is indeed cached there. In fact, if you use the Model-Glue application template, you will see this in the Controller.cfc init method:
All you need to do is place your Model CFCs here to cache them. An example:
Because the controller itself is cached, this CFC will also be cached.
Now for his second question:
I currently have an application.cfc in which i have code for each of the functions inside this component, onrequeststart(), on applicationstart() etc. How can I integrate this into MG?
There are a few answers to this. First off - Model-Glue will automatically call onRequestStart and onRequestEnd in each of your controller CFCs. So if you had 4 controllers, you actually get 4 different ways to run something on the start and end of each request.
As for onApplicationStart(), I kind of covered this in the first portion. The init method of each controller is run when the controller is created. This acts like a virtual onApplicationStart, and again, you have one for each controller. This is both good and bad. On one hand - I like how Model-Glue allows me to focus on each controller and it's own application startup/request startup work. On the flip side, that makes it a bit more difficult to see - quickly - exactly what is going on in your startup code. It's not impossible of course. You just need to look at multiple files.
As a side question - do you think it makes sense for Model-Glue to have a site wide Application and Request startup handler?
Comment 1 written by Rony Fayyad on 27 May 2007, at 7:12 PM
The reason I like Application.cfc is that it clearly indicated what was happening in my application via the functions available inside this component.
Now that each controller has a unique set of functions as found in the application.cfc, I find that the centralized way of identifying what is going on in the application ( via application.cfc ) is now going to be made harder.
To answer your side question ( if it was meant for me alone) was that i would like to see a state wide application and request startup handler. It just seems to make more sense to me, then breaking it down to individual controllers.
I am going to place the onsessionstart() in the main MG controller? Is that what i am supposed to be doing? I don't see the the need to have it in each controller, as opposed to the the onrequeststart().
Thanks,
Comment 2 written by Raymond Camden on 28 May 2007, at 12:28 AM
Comment 3 written by Rony Fayyad on 28 May 2007, at 5:51 PM
Now having to manually do it would be frustrating.
Also, what about on onSessionEnd() and onError()?
This is what i liked about the application.cfc, it did all this for you and all we had to do was written the code per function.
Comment 4 written by Raymond Camden on 28 May 2007, at 8:01 PM
Comment 5 written by Jazon on 23 January 2008, at 2:01 AM
Is the second time I'm going through the series, first time was a great learning experience, but now I'm paying close attention to things.
on the IIS section: shouldn't that be C:\Inetpub\wwwroot? you haveit backwards C:\wwwroot\inetpub
Thanks again!!!
Comment 6 written by Raymond Camden on 23 January 2008, at 6:28 AM
Comment 7 written by Jazon on 30 January 2008, at 10:40 PM
Comment 8 written by Troy on 30 January 2008, at 10:48 PM
Thanks in advance.
Comment 9 written by Troy on 30 January 2008, at 10:51 PM
Comment 10 written by Raymond Camden on 31 January 2008, at 6:21 AM
Comment 11 written by Paul Stewart on 4 July 2008, at 7:23 AM
Element MODELGLUE.FRAMEWORK is undefined in VARIABLES.
Comment 12 written by Raymond Camden on 4 July 2008, at 9:02 AM
Comment 13 written by Paul Stewart on 7 July 2008, at 5:33 AM
only 3 methods and no sign of init() method
--
LICENSE INFORMATION:
Copyright 2007, Joe Rinehart
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
VERSION INFORMATION:
This file is part of Model-Glue Model-Glue: ColdFusion (2.0.304).
The version number in parenthesis is in the format versionNumber.subversion.revisionNumber.
--->
<cfcomponent displayname="Controller" extends="ModelGlue.unity.controller.Controller" output="false">
<!---
Any function set up to listen for the onRequestStart message happens before any of the <event-handlers>.
This is a good place to put things like session defaults.
--->
<cffunction name="onRequestStart" access="public" returnType="void" output="false">
<cfargument name="event" type="any">
</cffunction>
<!---
Any function set up to listen for the onQueueComplete message happens after all event-handlers are
finished running and before any views are rendered. This is a good place to load constants (like UDF
libraries) that the views may need.
--->
<cffunction name="onQueueComplete" access="public" returnType="void" output="false">
<cfargument name="event" type="any">
</cffunction>
<!---
Any function set up to listen for the onRequestEnd message happens after views are rendered.
--->
<cffunction name="onRequestEnd" access="public" returnType="void" output="false">
<cfargument name="event" type="any">
</cffunction>
</cfcomponent>
Comment 14 written by Raymond Camden on 7 July 2008, at 6:19 AM
[Add Comment] [Subscribe to Comments]