So I was trying to get my BDD project SpecMaker working on Mono only to find out my usual IoC container of choice Castle Windsor does not play nice. StructureMap I’ve heard plays nice in Mono, and I know a bunch of people that use it, so I gave it a whirl.
My original Windsor configuration looked something like this:
kernel.Register(Component.For<IReportFactory>().ImplementedBy(factory)); //load implementation
WithService.FirstInterface(). //regardless of naming first interface is listed as service
I changed this to the what I thought was the StructureMap equivalent:
x.With<DefaultConventionScanner>(); //does NOT configure the first service interface
container.SetDefault(typeof(IReportFactory), new ConfiguredInstance(factory)); //specific implemenation
Ok so I ran my code and nearly none of my classes were registered only interfaces and classes that were in a pattern like ISpecFinder/SpecFinder. Looking at SM’s site this is actually expected behavior, and I was not able to find anything that would work the same way as I was used to. I’m not personally a fan of naming interfaces exactly like class names, so after looking around a bit at my options with SM and a brief perusal of Windsor’s source, I used StructureMap’s extensibility to come up with the following:
public void Process(Type type, PluginGraph graph)
if (!IsConcrete(type)) return; //only works on concrete types
var firstinterface = type.GetInterfaces().FirstOrDefault(); //grabs first interface
graph.AddType(firstinterface, type); //registers type
graph.AddType(type); //adds concrete types with no interfaces
public class IoCConfig
public virtual ISpecRunner InitializeRunner(Type factory)
var container = new Container(x=> x.Scan(
container.SetDefault(typeof(IReportFactory), new ConfiguredInstance(factory));
and perfecto! Everything now works as it did before and I was happy that something that wasn’t supported out of the box was so very simple to add myself. Finally, SpecMaker now appears to be working in mono and is nearing a release for me which I will share shortly.
Post Footer automatically generated by Add Post Footer Plugin for wordpress.