The Bitter Coder Tutorials, Binsor Style, Arrays

In the last post, I started doing the Bitter Coder tutorials, but using Binsor for the configuration.  This is the second in the series, and focuses on configuring arrays…the original is here.

So, our HolidayService tells us when we can go to the beach, yes?

namespace BitterCoder.Tutorials.Binsor.Core


public class HolidayService


private DateTime[] _holidays;

public DateTime[] Holidays


get { return _holidays; }

set { _holidays = value; }


public bool IsHoliday(DateTime date)


if (_holidays != null)


DateTime matchDate = date.Date;

foreach (DateTime test in Holidays)


if (test.Date.Equals(matchDate))


return true;




return false;




And the code to run this service:

static void Main(string[] args)


HolidayService holidayService = container.Resolve<HolidayService>();

DateTime xmas = new DateTime(2007, 12, 25);

DateTime newYears = new DateTime(2008, 1, 1);

if (holidayService.IsHoliday(xmas))

Console.WriteLine(“merry xmas!”);


Console.WriteLine(“xmas is only for management!”);

if (holidayService.IsHoliday(newYears))

Console.WriteLine(“happy new year”);


Console.WriteLine(“new year, you haven’t done all the work for last year!”);



And the config:

component “holiday.service”, HolidayService:






The array syntax in Binsor is the objects surrounding by parentheses.  If you has a list (or a List<DateTime>) you would have to use brackets ([ ]).  Also, we can new-up our dates here, minus the “new” keyword.  One more thing I’d like to mention, is I am constantly getting bit by not putting the colon (:) at the end of the component line, which you ONLY do if you are adding parameters.

BTW, if you take away the Holiday parameter (and the trailing : on the component line) you’ll get the default behavior, which shows up in the console as:

xmas is only for management!
new year, you haven’t done all the work for last year!

With the Holiday parameter (and the trailing : ) in the file, you get:

merry xmas!
happy new year

And we’re done with tutorial #2.

Next, we take a look at dictionaries…


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

3 responses to “The Bitter Coder Tutorials, Binsor Style, Arrays

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: