9

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?

nathfy
  • 687
  • 1
  • 9
  • 11
  • This bug has been reported to stuctureMap devs too on github - hoepfully they will update with fix: https://github.com/webadvanced/Structuremap.MVC4/issues/6 – nathfy Nov 01 '13 at 10:00

3 Answers3

9

In structuremap 3.x I used the following in my Registry, with success:

For<HelpController>().Use( ctx => new HelpController() );
Michael Fudge
  • 106
  • 1
  • 1
6

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.

seeking27
  • 115
  • 1
  • 3
4

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.

Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107
  • This worked like a charm. The only suggestion I would have is to separate the excluded assemblies in a separate call (in case you have many assemblies being excluded), i.e. - scan.ExcludeNamespace("System.Web"); – mirezus Dec 18 '13 at 20:32
  • This doesn't work for me at all. I need to use seeking27's suggestion. – Echiban Jun 26 '15 at 20:05
  • 1
    Please note that this was for an MVC 4 web app with basic assembly names. If you are using something different (MVC 5 or MVC 6), you millage may vary. – Maxime Rouiller Jun 29 '15 at 13:19