Unity.WebApi.UnityDependencyResolver equivalent in Unity.Mvc5

I had this piece of code working below in my .NET 4.5 application:

UnityConfig.cs

public static class UnityConfig { public static void RegisterComponents() { var container = new UnityContainer(); container.RegisterType<a_interfaces.IAMessageRepository, ARepository.AMessageRepository>(); DependencyResolver.SetResolver(new Unity.Mvc5.UnityDependencyResolver(container)); GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container); } } 

Global.asax

 public class WebApiApplication : System.Web.HttpApplication { protected void Application_Start() { UnityConfig.RegisterComponents(); AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); var _repo = (a_interfaces.IAMessageRepository)GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(a_interfaces.IAMessageRepository)); } } 

Now I need to configure .NET 4, I downloaded / installed Unity.Mvc4 (version 1.2). I get the following error on this line:

 GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container); The type or namespace name 'WebApi' does not exist in the namespace 'Unity' (are you missing an assembly reference?) 

Does anyone know what would be the equivalent code for .NET 4?

+6
source share

Source: https://habr.com/ru/post/985582/


All Articles