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这个文件,修改如下
![](https://images2015.cnblogs.com/blog/25237/201606/25237-20160605005143227-1214927815.png)
打开UnityConfig.cs这个文件,修改如下
![](https://images2015.cnblogs.com/blog/25237/201606/25237-20160605005404086-601210092.png)
![](https://images2015.cnblogs.com/blog/25237/201606/25237-20160605005404086-601210092.png)
在Global.asax中增加UnityWebActivator.Start();
![](https://images2015.cnblogs.com/blog/25237/201606/25237-20160605005710821-256869508.png)
![](https://images2015.cnblogs.com/blog/25237/201606/25237-20160605005710821-256869508.png)
Web.comfig:在<configuration></configuration>中加入
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<configSections> <section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,Microsoft.Practices.Unity.Configuration"/> </configSections>
然后配置:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<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>
最后在需要的地方调用