The Bitter Coder Tutorial, Binsor Style V – Configuration Parameters

(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 propertiesLive.boo

def DefineProperties():

configValues = {}

configValues[‘Name’]=”Live”

return configValues

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

//Change this to propertiesDebug.boo for Debug env

import file from propertiesDebug.boo

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 propertiesDebug.boo 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.

Advertisements

About Ruprict

I am a nerd that is a Nerd Wannabe. I have more kids than should be allowed by law, a lovely wife, and a different sense of humor than most. I work in the field of GIS, where I am still trying to find myself on the map. View all posts by Ruprict

One response to “The Bitter Coder Tutorial, Binsor Style V – Configuration Parameters

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: