Skip to content

Instantly share code, notes, and snippets.

@davidbreyer
Created March 21, 2014 13:13
Show Gist options
  • Save davidbreyer/9685920 to your computer and use it in GitHub Desktop.
Save davidbreyer/9685920 to your computer and use it in GitHub Desktop.
How to get Unity.Mvc5 and Unity.WebApi working together in a project
using Microsoft.Practices.Unity;
using System.Web.Http;
using System.Web.Mvc;
namespace WebApplication1
{
public static class UnityConfig
{
public static void RegisterComponents()
{
var container = new UnityContainer();
// register all your components with the container here
// it is NOT necessary to register your controllers
// e.g. container.RegisterType<ITestService, TestService>();
//Installing both Unity.WebApi and Unity.Mvc5 in a single project will cause the UnityConfig file to be overwritten.
//Include this line for Unity to resolve Mvc5 Controllers.
DependencyResolver.SetResolver(new Unity.Mvc5.UnityDependencyResolver(container));
//Include this line for Unity to resolve WebApi Controllers.
GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
}
}
}
Copy link

ghost commented Apr 7, 2015

thanks man, this should be documented by the nuget author

@mfsi-samu
Copy link

Thankyou

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment