Where is HttpConfiguration passed in? (MVC 4 beta)

Topics: Web Api
Feb 16, 2012 at 6:23 PM
Edited Feb 16, 2012 at 6:31 PM

There's bound to be a really simple answer to this but I'm trying to port an app from preview 6 to MVC 4 beta and stuck at first hurdle.

Using MVC 4 beta, I tried creating a new Web API project. Looking in Global.asax.cs there doesn't seem to be a mention of HttpConfiguration and the video showed a

public static void Configure(HttpConfiguration config)

But I didn't see where that was called from, in preview 6 it was something like:

            _factory = new HttpServiceHostFactory() { Configuration = config };           

But the HttpServiceHostFactory appears to have gone and so does SetDefaultHttpConfiguration :-|

In the beta, the Index.cshtml says it is passed into RegisterApis but I can't see that either.


Feb 16, 2012 at 9:41 PM

You will get it from the static property GlobalConfiguration.Configuration.

public static void Configure(HttpConfiguration config) {
config.ServiceResolver.SetResolver(new StructureMapDependencyResolver());

protected void Application_Start()  {

ViewEngines.Engines.Add(new RazorViewEngine());


Feb 16, 2012 at 11:52 PM

I haven't played with the new bits yet, but does this mean the config is a static member on some global class? This will be a problem when running multiple hosts, like I do in my integration tests.

But judging from the code above its stored in an IoC container, but if that is shared it will create the same problem.  I really need a way to specify the config per host instance.

Feb 17, 2012 at 2:07 AM
Right now, only Web Hosting has the global configuration limitation. Self hosting, memory hosting, use from unit tests, etc., has non-static configuration.
Feb 17, 2012 at 8:22 AM

Thanks Brad, thats great :)