Instead of writing:
// Global.asax.cs
WebApiConfig.Register(GlobalConfiguration.Configuration);
// WebApiConfig.cs
{
...
// Do not add any code below this line.
config.EnsureInitialized();
}
Do:
// Global.asax.cs
GlobalConfiguration.Configure(WebApiConfig.Register);
Where GlobalConfiguration.Configure is a static method that takes in a callback and, after calling it, calls EnsureInitialized for you, like so:
public static void Configure(Action<HttpConfiguration> configurationCallback) {
configurationCallback(GlobalConfiguration.Configuration);
GlobalConfiguration.EnsureInitialized();
}
Comments: I don't like the name "EnsureInitialized" ... it should actually be called "Initialize" because of the new Route Attributes. config.MapHttpAttributeRoutes(); since this actually creates a Initializer that now needs to be called for this to work. This is only a problem, when trying to get this working in a unit test ...
// Global.asax.cs
WebApiConfig.Register(GlobalConfiguration.Configuration);
// WebApiConfig.cs
{
...
// Do not add any code below this line.
config.EnsureInitialized();
}
Do:
// Global.asax.cs
GlobalConfiguration.Configure(WebApiConfig.Register);
Where GlobalConfiguration.Configure is a static method that takes in a callback and, after calling it, calls EnsureInitialized for you, like so:
public static void Configure(Action<HttpConfiguration> configurationCallback) {
configurationCallback(GlobalConfiguration.Configuration);
GlobalConfiguration.EnsureInitialized();
}
Comments: I don't like the name "EnsureInitialized" ... it should actually be called "Initialize" because of the new Route Attributes. config.MapHttpAttributeRoutes(); since this actually creates a Initializer that now needs to be called for this to work. This is only a problem, when trying to get this working in a unit test ...