Ayende @ Rahien

It's a girl

Binsor 2.0

All credit should go to Craig Neuwirt, for some amazing feats of syntax. He has managed to extend Binsor to include practically all of Windsor's configuration schema. This is important because previously we had to resort to either manual / ugly stuff or go back to XML (see: manual & ugly).

This is important because some of the more interesting things that you can do with Windsor are done using the facilities, and Craig has made sure that Binsor will support the main ones in a natural manner, including out of the box support for the standard configuration model.

Let us start by using the standard configuration model for a moment, the Active Record Integration Facility is expecting to be configured from XML, but we can configure it like this:

facility arintegration, ActiveRecordFacility:
		@isWeb = true, isDebug = true
		assemblies = [ Assembly.Load("My.Assembly") ]
		config(keyvalues, item: add):
			show_sql = true
			command_timeout = 5000
connection.isolation = 'ReadCommitted' cache.use_query_cache = false dialect = 'NHibernate.Dialect.MsSql2005Dialect' connection.provider = 'NHibernate.Connection.DriverConnectionProvider' connection.driver_class = 'NHibernate.Driver.SqlClientDriver' connection.connection_string_name = 'MyDatabase' end end

To compare, here is the equivalent  XML configuration.

<facility id="arintegration" 
	type="Castle.Facilities.ActiveRecordIntegration.ActiveRecordFacility, Castle.Facilities.ActiveRecordIntegration" 
	<add key="hibernate.cache.use_query_cache" value="true" />
	<add key="hibernate.connection.isolation" value="ReadCommitted" />
	<add key="hibernate.show_sql" value="false" />
	<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect" />
	<add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver" />
	<add key="hibernate.connection.connection_string_name" value="MyDatabase" />
	<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider" />

We don't have any significant reduction in the number of lines. This is mostly because we need to specify a lot of items for the facility to work, but we do have significant reduction in the noise that we have to deal with.

But, frankly, this isn't the best sample, let us take a look at the shortcuts that Binsor now provides, shall we?

Event Wiring

XML configuration:

      type="Castle.Facilities.EventWiring.Tests.Model.SimpleListener, Castle.Facilities.EventWiring.Tests" />

      type="Castle.Facilities.EventWiring.Tests.Model.SimplePublisher, Castle.Facilities.EventWiring.Tests" >
      	<subscriber id="SimpleListener" event="Event" handler="OnPublish"/>

And the Binsor configuration to match it:

component simple_listener, SimpleListener

component simple_publisher, SimplePublisher:
	wireEvent Publish:
		to @simple_listener.OnPublish

Now that is far clearer, isn't it?

Factory Support

XML configuration:

<component id="mycompfactory" 
      type="Company.Components.MyCompFactory, Company.Components"/>

<component id="mycomp" 
	type="Company.Components.MyComp, Company.Components"
	factoryCreate="Create" />

Binsor configuration:

component mycompfactory, MyCompFactory

component mycomp, MyComp:
	createUsing @mycompfactory.Create

Other new features:

  • Integrating Castle Resources, so now we can use Binsor over several files, which can be located anywhere, including assembly resources, for instance.
  • Easy support for startable and life styles.
  • Extension points for future needs.


Gian Maria
10/25/2007 06:03 AM by
Gian Maria

Ok, it is clear that you hate XML :D. I must admit that bindsor is really interesting, but I like the XML syntax too. It would be interesting making a pool to understand how many people feels confortable with XML and how many feels the need for a different syntax to handle configurations.

10/25/2007 06:13 AM by

Have you ever considered extracting Binsor from Rhino Commons to separate project?

Binsor adds great value to the Windsor container and having it as a separate project might make it easier for people to use, also a rhino commons or a separate binsor release that was built against castle RC3 would be great. It's not bad but it's a little work to get rhino commons to compile against latest caste and nhibernate release.

Paul Cowan
10/25/2007 06:49 AM by
Paul Cowan

I really like the look of binsor and have hated the bloated config files we have been producing in our apps for some time.

Is there a good binsor tutorial anywhere?



Ayende Rahien
10/25/2007 07:11 AM by
Ayende Rahien


Yes, I'll probably do that

Ayende Rahien
10/25/2007 07:15 AM by
Ayende Rahien



Paul Cowan
10/25/2007 11:49 AM by
Paul Cowan

Now one thing I would like to throw in the mix is............

One thing I like about the xml approach in conjunction nant is being able to pass in properties like the connection string from the command line and then use xmlpoke to set them dependant on the environment.

Now how would we do that with the binsor approach..............

Arne Claassen
10/25/2007 02:18 PM by
Arne Claassen

I have to admit that I must have been working with XML for too long, because I look at both versions and can grok the XML quicker and feel more confident that I wouldn't make syntax errors in writing it.

I won't argue about XML is verbosity, not being a language, etc. But for defining hierarchical configuration data, I have no problem reading it. And I don't have to learn a new syntax for every configuration I need to undertake.

I agree that once XML gets used to define logical things like if/else, etc. it's no longer config and XML is the wrong approach. But for most things that I need to configure, I'd rather them all be XML, because it reduces the learning curve and I can parse/generate/author it with one set of tools.

Mind you, I'm not promoting configuration over convention, but just saying if there is configuration to be done, I like the XML syntax.

Ayende Rahien
10/25/2007 02:23 PM by
Ayende Rahien

What I think that people are missing is that those are just the icing on the cake.

The main advantages are that you get rid of repeated stuff. This just mean that you can get read of even more stuff

Tom Opgenorth
10/25/2007 03:40 PM by
Tom Opgenorth

Hmmm, I guess I should go get Binsor 2.0 and update my quick intro to Binsor on my website.

10/25/2007 05:49 PM by

i have to second binsor being it's own project...

my environment is pretty open to open source(we're using nhibernate, windsor and nlog in our project)..... but introducing the terms "binsor" AND "rhino commons" just to get slimmer config files is a difficult argument to make.

Paul Cowan
10/26/2007 06:52 AM by
Paul Cowan

I guess what I want to know is, can I use binsor to load all my services <component id='blah' type=''...

And still keep the xml for my facilities?

Is this possible.

Ayende Rahien
10/26/2007 10:40 AM by
Ayende Rahien


Yes, you can.

After you init the container,

BooReader.Read(container, "boo file")

David Gardiner
10/28/2007 11:47 AM by
David Gardiner

I've tried to document the necessary steps to compiling the code to get this to run.


Comments have been closed on this topic.