Application Configuration: How Do You Do It?

There are lots of ways you can configuration an application. You can define server, application, or request variables in your Application.cfm file; you can load an external XML file; you can use an INI, or initialization, style file; you can store you application’s configuration parameters in a database (although often, configuration data contains data source information, so that’s a bit like locking your keys in your car). You can even try to dynamically determine your configuration based on your environment.

I find myself using a little of everything. Primarily, I use the init custom tag from DRK 3 and put configuration in my Application.cfm file. I actually like using code to express my application’s configuration as opposed to text formats like INI or XML because code is more flexible and often less verbose. If it gets out of control and I want to externalize huge lists of things like products or countries or something, I will use an XML file or store them in a database table, depending on how dynamic I need them to be, and whether I have time to build an interface for editing the information in the database, which I usually don’t.

What techniques to you use in different circumstances, and why?

7 Responses to Application Configuration: How Do You Do It?

  1. paulH says:

    i still use .ini (.properties) files. i used to put things in code, simple & fast but when i re-worked things in any major way, simple & fast became slow & painful. xml’s a bit too much & is, in my opinion, not for humans. anyway thats my 5 baht worth.

  2. I use a mix, but I’m moving all of my config files toward XML.

  3. Andy says:

    I have a standard bit of code that makes up my Application.cfm file, whether this is code within the actual file itself or via an included ‘server wide environment’ file.Each specific application then has it’s own included file within Application.cfm with settings for whatever it requires, e.g. Datasources, etc.It’s a set up I’ve used for a while now and for me, it works really well.

  4. Nathan Strutz says:

    I’ve got an ApplicationInitialization.cfm (yeah, i spelled it out) that checks for IsDefined(…) and locks/prevents double-locks before it sets some variables, runs some queries and creates all my application params. It’s included in my Application.cfm for the visitor area of my site.It seems to work pretty good, along with my ApplicationRestart.cfm, which has 3 buttons – reset cached queries (the db admin loves this), reset application variables (to impress the other cf coders) and reset all (for emergencies).any/all code available on request.

  5. Rich Ziade says:

    I use an XML config file. It’s intentionally generic, so if you add more key/value pairs into the XML, the cfc simply loops through whatever’s there and populates the application scope.

  6. It seems like the XML method would work best if you coded them all in WDDX, then simply import them straight into the application scope. Not to dis your method, rich, but using a cfc to loop through your XML file seems elaborate. Or am I missing the point?

  7. Quote: “I use a mix, but I’m moving all of my config files toward XML.”Thats indeed the best way to go. I’ve done the same on my sites.