Created
April 16, 2015 16:57
-
-
Save saip106/4e93c617a399c17ce304 to your computer and use it in GitHub Desktop.
StructureMap Web API Bootstrapping
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected void Application_Start() | |
{ | |
var container = new Container(); | |
//Do registration here | |
var config = GlobalConfiguration.Configuration; | |
config.Services.Replace(typeof(IHttpControllerActivator), new ServiceActivator(config, container)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ServiceActivator : IHttpControllerActivator | |
{ | |
private readonly IContainer _container; | |
public ServiceActivator( | |
HttpConfiguration configuration, | |
IContainer container) | |
{ | |
_container = container; | |
} | |
public IHttpController Create( | |
HttpRequestMessage request, | |
HttpControllerDescriptor controllerDescriptor, | |
Type controllerType) | |
{ | |
return _container.GetInstance(controllerType) as IHttpController; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment