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:

<code>

<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" />
</controller>

</code>

<em>Caveat</em>

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.

<em>Enabling it</em>

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.

<em>What about "sub-applications?"</em>

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.