The Bitter Coder Tutorials, Binsor Style III: Dictonaries July 14, 2008
Posted by ruprict in WCF.Tags: Binsor, Windsor
trackback
Time for Part III in the Binsorization of the Bitter Coder tutorials. The original tutorial is here.
The original tutorial created a class to handle word substitution, which looked a lot like:
public class AliasService
{
private Dictionary<string, string> _aliases;
public Dictionary<string, string> Aliases
{
get { return _aliases; }
set { _aliases = value; }
}
public string Evaluate(string term)
{
if (_aliases == null) return term;
while (_aliases.ContainsKey(term))
{
term = _aliases[term];
}
return term;
}
}
And the application code:
static void Main(string[] args)
{
AliasService aliasService = container.Resolve<AliasService>();
string sentence = “a dog ate my homework”;
foreach (string word in sentence.Split(new char[] { ‘ ‘ }, StringSplitOptions.RemoveEmptyEntries))
{
Console.Write(“{0} “, aliasService.Evaluate(word));
}
}
Now the Binsor:
import System
import System.Reflection
import System.Collections.Generic
import BitterCoder.Tutorials.Binsor.Core
aliases=Dictionary [of string, string]()
aliases['dog']=”duck”
aliases['ate']=”broke”
aliases['homework']=”code”
component “aliases.service”, AliasService:
Aliases=aliases
So, we have a bit of strange syntax to get a generic Dictionary, but then it becomes very natural to create the entries. Also, we don’t have to worry about the type converters that Alex mentions in his tutorial.
Running the code gives us:
a duck broke my code
All good. Up next is Switching Configurations…

Hi Ruprict, any idea how to configure SortedList whose elements are components register on the container in binsor.
Class1
{
public SortedList Proxies
{
get { return _proxies;}
set { _proxies = value; }
}
}
I would like to do something like:
component ‘proxy1′, ICrudTransfer
component ‘proxy2′, ICrudTransfer
_proxies = SortedList[of string, ICrudTransfer]()
_proxies['url1']=@proxy1
_proxies['url2']=@proxy2
component ’service’, ICrud, Crud:
Proxies = _proxies
Which it doesn’t work.
I would like to use such as properties, arrays or list.
component ’service’, ICrud, Crud:
CrudProxy = @proxy3
CrudProxies = (@proxy1 , @proxy2)
Thanks and regards