Monday, February 2, 2009

Application.cfc and Frameworks

im working on a utility and am setting up a little session state management. I have a request from a customer like this "when we choose a question type of A, can it remember that for the next one record i add?". Of course, a common request, what i would referr to as state management. Keep the last answer provided by the user via the interface and use it to inform the state of the interface. Session variables come immediatly to mind.

I set off to implement this solution. I thought about it for a little while first, heavylifting, my biggest question was where to lookup and update the session variable. I did not want to do it on the view page, but rather somewhere in a *session object. My thinking brought me into the Application.cfc, which is a special *framework like component that Coldfusion provides that have built in plugin points. This means there are points in a request where the developer can interceed and do some kind of processing, testing etc. These built in functions include application start and end, session start and end, request state and end. This is pretty handy IF you ARE NOT ALLREADY using a framework.

I am using machii and so have a means already to interceed where i need to. Additionaly, the framework allows me to interceed in the event that i want, not all the events. That feels a little better than sticking the test in a OnRequest function. I could put logic in the OnRequest and have it only perform when needed - but even then, that wrapper logic would be read on EVERY request. My framework allows me to place the same test in a listener or service request that is ONLY read when i explicitly call for it.

The framework adds overhead, but pays for itself in many ways, including this one.

Bottom line - dont expect to use Application.cfc or the old school Application.cfm IF you are using a framework. This is a quote from mega smart Sean Corfield.

"It doesn't really. Frameworks generally provide their own plugin points and ignore Application.cfm - and they pretty much ignore Application.cfc as well. Perhaps future versions of the frameworks will support / integrate with Application.cfc? "

No comments: