Skip to content

Instantly share code, notes, and snippets.

@eshapovalova
Last active August 29, 2015 14:19
Show Gist options
  • Select an option

  • Save eshapovalova/b742bc4faa61579c6cc7 to your computer and use it in GitHub Desktop.

Select an option

Save eshapovalova/b742bc4faa61579c6cc7 to your computer and use it in GitHub Desktop.
Web API Activator
public class UnityApiControllerActivator : IHttpControllerActivator
{
private readonly IUnityContainer _container;
public UnityApiControllerActivator(IUnityContainer container)
{
_container = container;
}
public IHttpController Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
{
return (IHttpController) _container.Resolve(controllerType);
}
}
var container = new UnityContainer();
GlobalConfiguration.Configuration.DependencyResolver = new UnityDependencyResolver(container);
container.RegisterInstance<IHttpControllerActivator>(new UnityApiControllerActivator(container));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment