Binsor From Embedded Resource or Any Stream

Jeremy Jerrell has a couple of great posts about Binsor over at Digital Blasphemy.

In his latest he shows how to Embed the Binsor in your assembly, but IMO his implementation is all wrong. If not all wrong, then it is a hack at best. Maybe Jeremy didn’t know that Rhino.Commons is open source.

IMNSHO Files are code smell. Should it really be the responsibility of class XYZ to open and use that file? Why not pass a stream and move the responsibility somewhere else.

Now in the case of Binsor there is good reason to accept a filename. Binsor allows you to include other files in the same directory as the Binsor file. This feature doesn’t work with my supplied solution, nor does it work with Jeremy’s, unless you manually extract each file first. IMO this defeats the purpose of embedding the Binsor config as a resource.

I couldn’t let it go, so I added a method override to BooReader.Read which accepts a stream as a parameter. Due to the nature of Binsor, you still need to name your boo module, so any string name can be passed as well.

public static void Read(IWindsorContainer container, Stream stream, string name)

The use case is very simple:

_container = new RhinoContainer();

Stream stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream(“Rhino.Commons.Test.Binsor.EmbeddedWindsor.boo”);

BooReader.Read(_container, stream, “EmbdeddedWindsor”);

Because Rhino.Commons is open source I was able to use TortoiseSVN to create a patch and mail it to Ayende. If you can’t wait, the patch will be available here for a while.

1 thought on “Binsor From Embedded Resource or Any Stream”

Comments are closed.