Unity4.0配置
关于Unity4.0的使用:
一 安装Unity
在程序包管理器控制台输入命令:Istall-Pckage unity.mvc
安装后会在App_Start中生成UnityConfig.cs 和UnityMvcActivator.cs 两个文件,打开UnityConfig.cs这个文件,修改如下
在程序包管理器控制台输入命令:Istall-Pckage unity.mvc
安装后会在App_Start中生成UnityConfig.cs 和UnityMvcActivator.cs 两个文件,打开UnityConfig.cs这个文件,修改如下

打开UnityConfig.cs这个文件,修改如下


在Global.asax中增加UnityWebActivator.Start();


Web.comfig:在<configuration></configuration>中加入

<configSections> <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,Microsoft.Practices.Unity.Configuration"/> </configSections>
然后配置:

<unity xmlns="http://schemas.microsoft.com/practices/2010/unity" > <!--版本--> <assembly name="LongIBLL"/> <assembly name="LongBLL"/> <assembly name="LongIDAL"/> <assembly name="LongDAL"/> <!--命名空间--> <namespace name="LongIBLL"/> <namespace name="LongBLL"/> <namespace name ="LongIDAL"/> <namespace name ="LongDAL"/> <container> <!--IBLL映射BLL类--> <register type="ILongRolesService" mapTo="LongRolesService"/> <register type="ILongManagersService" mapTo="LongManagersService"/> <register type="ILongNewsService" mapTo="LongNewsService"/> <register type="ILongModulesService" mapTo="LongModulesService"/> <register type="ILongPermissionModulesService" mapTo="LongPermissionModulesService"/> <register type="ILongPermissionService" mapTo="LongPermissionService"/> <!--IBLL<T>映射BLL类<T> 泛型注入--> <register type="IBaseService[]" mapTo="LongBaseService[]"/> <!-- IDAL映射DAL--> <register type="ILongRolesRepository" mapTo="LongRolesRepository"/> <register type="ILongManagersRepository" mapTo="LongManagersRepository"/> <register type="ILongNewsRepository" mapTo="LongNewsRepository"/> <register type="ILongModulesRepository" mapTo="LongModulesRepository"/> <register type="ILongPermissionModulesRepository" mapTo="LongPermissionModulesRepository"/> <register type="ILongPermissionRepository" mapTo="LongPermissionRepository"/> <!-- IDAL<T>映射DAL<T>泛型注入--> <register type="IBaseRepository[]" mapTo="LongBaseRepository[]"/> </container> </unity>
最后在需要的地方调用