[Commandbox 5.1.1] Where to set Application and Session variables

I am migrating a legacy application to Coldbox.

Normally I would create my Application and Session Variables in the onApplicationStart() and onSessionStart() functions.

Would I do the same with Coldbox or is there a convention for managing Application and Session wide variables that is different.

As for the functions that I normally place in Application.cfc, would I be better off having those in a separate Class that is injected into a application scope property?

If I do modify the Application.cfc is this going to be a problem when upgrading Coldbox?
Local scope variables will be set in the handler code correct?


Application-scoped variables should probably become Coldbox settings or WireBox singletons, depending on what the variable is. I’d need to know more about what you’re putting in the session scope. but you can create an onSessionStart handler in ColdBox. If you are storing CFCs like user CFCs in the session scope, then check into WireBox’s scopes where it can do this for you.

As far as the functions in your Application, I’d need to know what they are. Chances are they can be placed in a utility class in the models folder and injected wherever you need them.

Please read this doc, you can set Implicit Event Settings which can be pointed to a handler


We have a number of user settings, that control look and feel, as well as login status stored in session, no CFCs.

Do these run after the referenced functions or in place of them?

What is the advantage to making them coldbox settings, can a Wirebox Singleton represent a single unique value like a string or are they always classes?

The Coldbox handlers such as onSessionStart run inside of the Application.cfc’s onSessionStart method. There is boilerplate there that taps the framework to execute it’s handlers. The benefit is your Coldbox handlers run inside of the framework and have proper access to helper methods, view renderings, injections, etc.

What is the advantage to making them coldbox settings,

  • The are encapsulated inside the controller so the framework can control them
  • they are reloaded automatically when you reinit the framework
  • They can be influenced by environment detection
  • You can use helpers in the coldbox.cfc to access env vars and java system properties to set them
  • They are injectable by Wirebox
  • They are accessible in every handler, view, layout, and interceptor via the getSetting( ‘name’, ‘default’ ) method
  • They can be mocked more easily in unit and integration testing

can a Wirebox Singleton represent a single unique value like a string or are they always classes?

Any WireBox mapping can be a singleton and a mapping can point to anything including a static variable, but typically singletons means a CFC instance. There’s no point in having a singleton string. Just use a Coldbox setting.

The fact that they are more easily mocked is enough to sell me right away.