Castle Dictionary Adapter

Fri Oct 29 2010 by MarkP

I recently discovered a fairly under-utilised tool in the Castle project called the Castle Dictionary Adapter. The basic premise it to be able to create a type wrapper around dictionaries.

This is especially useful in web applications where many untyped objects exist which rely heavily on "magic strings" to be able to reference them. An primary example is when accessing AppSettings data in the web.config file.

Previously in my application, I was using a Configuaration helper class which passed in the string value to determine the value in the AppSettings data. Using the Castle Dictionary Adapter you can use an interface to define the values as properties and then map the values using the Dictionary Adapter (see links below for examples).

One thing I did notice which caused an issue was the fact that any relative paths defined in my web.config were no longer working when I changed to use the Dictionary Adapter on my development machine. I am not sure if this was some issue in relation to the Dictionary Adapter or specific to my application in general.

Further Reading:
Castle Dictionary Adapter
Improving Testability with the Castle Dictionary Adapter
Castle Casts - Dictionary Adapter
Castle Dictionary Adapter Overview

Tags: Castle  

Comments

Required fields are marked with required

The form could not be submitted please check the errors and resend:
Post a Comment