MG3: Application.cfc integration

Towards the end of last week, I finished adding Application.cfc integration into Model-Glue 3. I've taken a few passes at it, and finally hit upon a solution I'm happy with.

The short of it is that working with onSessionStart, onSessionEnd, and onApplicationStart within a Model-Glue 3 application is just like working with earlier Model-Glue application's onRequestStart or onRequestEnd broadcasts: just listen for it and do what you need to do!

For example, if you had a UserCountController that incremented and decremented the number of current sessions, you could subscibe its functions like so:

<controller name="UserCountController" type="com.myapp.controller.UserCountController>
<message-listener message="
onApplicationStart" function="resetUserCount" />
<message-listener message="
onSessionStart" function="incrementUserCount" />
<message-listener message="
onSessionEnd function="decrementUserCount" />



When you listen for onSessionEnd, you obviously don't have a URL or FORM scope to populate into the event. Instead, the only defined event value is "sessionScope," which is (you guessed it) the session scope of the expiring session.

Enabling it

There's now an Application.cfc as part of the application template. If you'd like to use this in an upgraded application, I believe you can just replace your Application.cfm with the CFC from the new template, modifying the copy with your application's name, settings, etc.

What about "sub-applications?"

In a "sub-application" setup, you may have more than one Model-Glue application in a given application scope, using ModelGlue_APP_KEY to keep them separate. In another situation, you may have a non-Model-Glue application sharing an application scope with Model-Glue.

The implementation used accounts for both. As long as the Application.cfc from the new application template is used, it'll introspect the application scope (using the ModelGlueFrameworkLocator, inspired by ColdSpring's BeanFactoryUtils) to find all instances of Model-Glue, firing the appropriate onSessionStart/End/etc. events in all of your applications.

In other words, if you've got two Model-Glue apps sharing the same application scope and a session starts orends, both will have their onSessionStart/End mechanics fired.

Related Blog Entries

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Is this project still active? Its been a really long while since the beta and the "comming soon" for the documentation on MG3, I am a ColdFusion developer with Ruby on Rails experience and was looking forward for this framework, but I dont see much activity here.
# Posted By Raul Riera | 7/20/08 4:37 PM
© 2020 Joe Rinehart
BlogCFC was created by Raymond Camden. This blog is running version