The Bitter Coder Tutorial, Binsor Style V - Configuration Parameters

Mon, Jul 28, 2008 2-minute read

(Sorry about the delay in the tutorials, but I took a week of vacation and my wife wouldn’t let me near the computer…)

Previous posts in the series:

In tutorial #5, Alex focuses on configuration parameters.  He creates 2 properties configuration files (live and debug) and then does an ‘include’ in the configuration XML to pull in which one he wants, commenting out the other.  I am gonna try something similar here.

Boo/Binsor allows you to include files, but there is seemingly an issue.  Any variables defined in the included file are ignored, which I found odd (scope issue?)  Anyway, I then found this post from Ayende and knew I had to get a bit creative.  My inspiration was yet another post from Ayende.  My solution was to create 2 files (live and debug, like Alex) and import them (like Alex.)   In each file is a function called DefineProperties() that returns a hash of property values.

Here is

def DefineProperties():

configValues = {}


return configValues

So, I create a hash, put in a ‘Name’ key and value, then return the hash.  Now I have to import the file and then call the function.  Here’s what I added to the file:

//Change this to for Debug env

import file from

configEnvironment = DefineProperties()

This is right under the namespace import statements.  Now I can use the configEnvironment hash in my component registrations:

component “class.conn”, ConfigDepot:

ConnectionString = connectionString

ConfigEnvironment = configEnvironment[‘Name’]

You could easily add as many key/values as needed or put other logic in the DefineProperties() function.  The defines the same function, but with different values.

It’s not incredibly elegant, and I am betting Ayende or one of the other big brains could do it cleaner/better/stronger, but this works.

Next time….lifestyles.