Skip to content

Instantly share code, notes, and snippets.

@benfoster
Created October 7, 2012 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save benfoster/3847790 to your computer and use it in GitHub Desktop.
Save benfoster/3847790 to your computer and use it in GitHub Desktop.
Injecting HttpRequestMessage in ASP.NET Web API
public IHttpController Create(
HttpRequestMessage request,
HttpControllerDescriptor controllerDescriptor,
Type controllerType)
{
var scope = request.GetDependencyScope() as StructureMapDependencyScope;
// Inject the current request into the underlying container
scope.Container.Inject<HttpRequestMessage>(request);
return scope.GetService(controllerType) as IHttpController;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment