Structure Map Fluent Interface

time to read 2 min | 343 words

Now, I am not a user of StructureMap, but the interface looks cool:

// Add an instance with properties
registry.AddInstanceOf<IWidget>()
  .WithName("DarkGreen")
  .UsingConcreteType<ColorWidget>()
  .WithProperty("Color").EqualTo("DarkGreen");

Jeremy calls it a DSL, but I don't think that it is the correct term, it is just using a diffeerent (and better) approach for coniguring it with code.

The main problem I have with this is that it is something that breaks down when you need the complex stuff, because you are working within the constraints of the compiler. I have worked quite a bit on the Rhino Mocks, and I have gotten very annoyed with the compiler at numerous occasions.

Take a look here for a look how easy it is to use Rhino Mocks when you can actually modify the language to do this.

The problem with limiting yourself to the compiler is that you are forced to expressed declarative intention using imperation notation. The above using Binsor would be:

Component( "DarkGreen", IWidget, ColorWidget, Color: DarkGreen)

Frankly, I don't think that Jeremy's interface can get much better (short of starting to use Eq(), Lt() to make it shorter). I would rather step outside the confines of the compiler than stay within its limitations*.

* Yes, I know that there are a lot of people who would disagree with me on that one.