Intro to Binsor

What Is It?

Binsor is, in the words of it's creator, "The Boo DSL for Windsor".  I think a more accurate description is an executable config file for your application using both Boo and Windsor.  Windsor is a great tool, but sometimes the XML config files for it become a bit - oppressive.

If you're not familiar with Windsor from the Castle Project,  you should probably first go get familiar with it, and then come back here.  I'd also suggest becoming familiar with Inversion of Control Containers and the Dependency Injection pattern.  Without this basic foundation, you might not fully appreciate what Binsor does.

Here is a brief description of what I did to get started with Binsor. 

UPDATE:  I don't know how relevant / accurate this is for Binsor 2.0.

Get Rhino.Commons

The first thing that you will need to go is to go and get Rhino.Commons.  I'd suggest getting get the code from SVN and building it yourself, it's pretty simple todo.  To get you started, I've got a build of Rhino.Commons here, along with it's dependencies

Add the References in Your Project 

Once you have the binaries, you will need to add the appropriate references for your project.  In particular, you will need a reference to Rhino.Commons.DLL, log4net.DLL, and NHibernate.DLL.

One thing that might trip you up is if you maintain your own build of log4net.dll.  I had the problem where Rhino.Commons.DLL was expecting a version of log4net.DLL to be loaded that was different from mine.  Either just use the log4net.DLL that comes with Rhino.Commons, or specify in your projects that they don't need a specific version of log4net.DLL.

Create Config File 

Next you need to create a "config file".  This isn't in XML like a traditional Windsor config file.  It is a text file, but it is not XML.  It is a Boo script.  Currently there isn't support for Boo in Visual Studio 2005, but that might change. If you want an IDE that supports boo,  #Develop does support.  Otherwise, just use a text editor of your choice.

In Your Project

Inside your program you will need load the config file.  Here is a snippet:

   1:  using System;
   2:  using System.Windows.Forms;
   3:   
   4:  using Castle.Windsor;
   5:   
   6:  using Rhino.Commons.Binsor;
   7:   
   8:  namespace GettingStartedPart1
   9:  {
  10:      using System;
  11:   
  12:      public class App
  13:      {
  14:          public static void Main()
  15:          {
  16:              IWindsorContainer container = new WindsorContainer();
  17:              BooReader.Read(container, "Windsor.boo");
  18:   
  19:              Form1 form = (Form1) container[typeof (Form1)];
  20:   
  21:              // Use the component
  22:              Application.Run(form);
  23:   
  24:              // Release it
  25:              container.Release(form);
  26:          }
  27:      }
  28:  }

A quick explaination of what we did:  In line 16, we instantiated a new IWindsorContainer.  We then provided that to the BooReader, along with name of our binsor config file.  BooReader will initialize our IWindsorContainer.  From this point, we just use Windsor like we always did.  In this sample, line 19 asks Windsor to get us an instance of Form1, we which we then run in our application.  When the application is done with Form1, we get Windsor to release it in line 25.

As an aside, inside of Rhino.Commons is a class call RhinoContainer which does basically the same thing as lines 16 & 17 above:

   1:  using System;
   2:  using System.Windows.Forms;
   3:   
   4:  using Castle.Windsor;
   5:   
   6:  using Rhino.Commons;
   7:   
   8:  namespace GettingStartedPart1
   9:  {
  10:      using System;
  11:   
  12:      public class App
  13:      {
  14:          public static void Main()
  15:          {
  16:              IWindsorContainer container = new RhinoContainer("Windsor.boo");
  17:   
  18:              Form1 form = (Form1) container[typeof (Form1)];
  19:   
  20:              // Use the component
  21:              Application.Run(form);
  22:   
  23:              // Release it
  24:              container.Release(form);
  25:          }
  26:      }
  27:  }

Sample Application

I've take the sample project from the Windsor Getting Started, and "binsor-fied" it.  Some slight modifications were made to it, but I hope that you will still get the idea of how Binsor works.  You can download it from here

Appendix:  Building Rhino.Commons

Coming soon.  It's pretty simple actually.