The Bitter Coder Tutorials, Binsor Style III: Dictonaries

DictionaryImage via Wikipedia

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]()




component “aliases.service”, AliasService:


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…

Zemanta Pixie

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 Tutorials, Binsor Style III: Dictonaries

  • ppcanodehuelva

    Hi Ruprict, any idea how to configure SortedList whose elements are components register on the container in binsor.

    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]()

    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

Leave a Reply

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

You are commenting using your 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: