Created
March 21, 2014 13:13
-
-
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
This file contains 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
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thanks man, this should be documented by the nuget author