UnityConfig.cs文件,同时将unity.mvc5和unity.webapi保持在同一项目中

时间:2018-11-22 14:36:45

标签: asp.net-mvc asp.net-web-api

Nuget软件包管理器仅保留一个UnityConfig.cs文件,因此我需要将它们合并,以便两个软件包都能工作。我该怎么办?

1 个答案:

答案 0 :(得分:0)

using Microsoft.Practices.Unity;
using System.Web.Http;
using System.Web.Mvc;
using Unity;

namespace project_name
{
    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>();

            DependencyResolver.SetResolver(new Unity.Mvc5.UnityDependencyResolver(container));

            GlobalConfiguration.Configuration.DependencyResolver = new Unity.WebApi.UnityDependencyResolver(container);
        }
    }
}