I followed the instructions here to add the webApi.HelpPage area and views to an existing project, which uses structureMap - but when accessing the /Help url:
StructureMap Exception Code: 202 No Default Instance defined for PluginFamily System.Web.Http.HttpRouteCollection, System.Web.Http, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
So I'm missing something on the structureMap configure:
ObjectFactory.Configure(x => x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.AssembliesFromApplicationBaseDirectory();
scan.AddAllTypesOf<IHttpModule>();
scan.WithDefaultConventions();
}));
Can anyone point a structureMap newbie in the right direction?
In structuremap 3.x I used the following in my Registry, with success:
For<HelpController>().Use( ctx => new HelpController() );
I also had the same problem. What I found to be the issue was that there are two constructors in the HelpController. One that takes an HttpConfiguration, and another that takes a GlobalConfiguration. I forced StructureMap to call the GlobalConfiguration constuctor by making the Http constructor private.
public HelpController()
: this(GlobalConfiguration.Configuration)
{
}
private HelpController(HttpConfiguration config)
{
Configuration = config;
}
That seemed to do the trick.
Ensure to skip System.Web.* assemblies from your assembly scanner.
ObjectFactory.Configure(x => x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.AssembliesFromApplicationBaseDirectory(assembly => !assembly.FullName.StartsWith("System.Web"));
scan.AddAllTypesOf<IHttpModule>();
scan.WithDefaultConventions();
}));
It is a bug and we both commented on the Github of StructureMap. I hope that we won't be needed this in the future but for now, it's a quickfix.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With