When migrating from CF2016 engine to Lucee, it seems I can no longer use constants in the application scope.
I set the following constants in Application.cfc, which loads them without error:
var Application.companyName = “alpha”;
// Set application date and datetime database storage format
var Application.dbDatetimeFormat = “yyyy/mm/dd HH:nn”;
But when I try to use those constants within my code such as “Application.dbDatetimeFormat” for example, Lucee triggers an error. The Adobe engine never did.
What is now the best practice to deal with constant declaration in Lucee?
Cfml has no concept of “constants” so I’m not sure what you’re talking about. Also, why are you using the var keyword. I would expect that to create local.application.foo which clearly isn’t what you want. Sounds like a bug in Adobe.
Hi Brad, issues with Application.cfc are resolved.
1 - I load a component called TenantCompany with Application.cfc, in which I set all the (constant value) parameters I need in the Application scope.
2 - For Java components, I use the Coldbox Javaloader module.
Glad to hear. Maybe this goes without saying but for what it’s worth, none of what you’re doing is following ColdBox best practices. WireBox should be creating all of these objects and the you should be asking WireBox for them or injecting them where necessary. (The word singleton applies here to mean the same basic thing I think you meant by “constants”)
Now, if you’re integrating ColdBox into a legacy site and just need these variables temporary as a stop gap until everything is converted, that is understandable. But I just wanted to make it clear that in using ColdBox and Wirebox, you really shouldn’t be creatinga by parts of your app in the Application.cfc.
Brad, OK. I think I finally got it… a singleton object is in fact living in the application scope and managed by Wirebox, which is the reason why I no longer need to load any component whatsoever in Application.cfc.
Well, more specifically, the reason you shouldn’t be creating CFCs in the Application.cfc file is because ColdBox/WireBox have conventions for creating CFCs.
The reason you shouldn’t be directly creating CFC objects, is because WireBox should be doing all that for you (IOC stands for Inversion Of Control)
And yes, a singleton is persisted in WireBox, which is persisted ultimately in the application scope, so you don’t ever have to worry about storing a CFC anywhere. Simply tell WireBox how long you want that CFC to live and then, when you need an instance of it, ask WireBox to give it to you. WireBox will take care of the rest. IOC!
Note, WireBox is not just limited to CFC’s, it can create instance of Java classes for you as well if you like.
I’m also a little surprised that “var application.foo =…” doesn’t actually create that variable in local.application.foo. You needn’t use var when setting a variable in an explicit scope.