/// <summary> /// 负责调用 autofac框架实现业务逻辑 和 数据仓储层程集中的类型对象的创建 /// 负责创建MVC控制器类的对象(调用控制器中的有残构造函数) , 接管DefaultControllerFactory的工作 /// </summary> public static void Register() { // 1.0 实例化autofac的创建容器 var bulider = new Autofac.ContainerBuilder(); // 2.0 告诉AutoFac 框架, 将来要创建的控制器类存放在哪个程序集(CRM.Site) Assembly controllerAss = Assembly.Load("CRM.Site"); bulider.RegisterControllers(controllerAss); // 3.0 告诉 autofac注册仓储层所在程序集中 所有类的对象的 对象实例 Assembly respAss = Assembly.Load("CRM.Repository"); //创建respAss中所有类 instance 以此的实现接口 存储 bulider.RegisterTypes(respAss.GetTypes()).AsImplementedInterfaces();//.InstancePerHttpRequest(); // 4.0 告诉 autofac注册业务逻辑层所在程序集中 所有类的对象的 对象实例 Assembly serAss = Assembly.Load("CRM.Services"); //创建respAss中所有类 instance 以此的实现接口 存储 bulider.RegisterTypes(serAss.GetTypes()).AsImplementedInterfaces(); //.InstancePerHttpRequest(); // 5.0 创建一个autofac 的容器 var container = bulider.Build(); // 5.01 将container 对象 缓存到 httpRuntime.cache 中, 并且 永久有效 CacheMgr.SetData(Keys.AutofacContainer, container); // Resolve 方法可以从autofac 容器中获取IsysuserInfoSerices 的 具体实现类的实体对象 // 6.0 将MVC的控制器对象实例 交由autofac来创建 DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
public static void RegisterDependencies() { // TODO:使用autofanc实现的工厂替换MVC底层默认控制器工厂 //TODO:还用autofac将所有的接口初始化 //1.0 实例化autofac的容器创建者的对象 var bulider = new ContainerBuilder(); HttpConfiguration config = GlobalConfiguration.Configuration; //2.0 实例化仓储层的所有接口的实现类的对象,以接口和实现类的对象形式存储在autofac容器内存中 //bulider.RegisterType(typeof(sysFunctionRepository)).As(typeof(IsysFunctionRepository)); //bulider.RegisterType(typeof(sysKeyValueRepository)).As(typeof(IsysKeyValueRepository)); // bulider.RegisterTypes(Assembly.Load("Doctors.Services").GetTypes()).AsImplementedInterfaces(); //3.0 实例化Services(业务逻辑层的接口) //bulider.RegisterType(typeof(sysFunctionServices)).As(typeof(IsysFunctionServices)); //bulider.RegisterType(typeof(sysKeyValueServices)).As(typeof(IsysKeyValueServices)); bulider.RegisterTypes(Assembly.Load("Doctors.Services").GetTypes()).AsImplementedInterfaces(); //4.0 告诉autofac将来创建控制器类对象的程序集名称为什么 Assembly ass = Assembly.Load("Doctors"); bulider.RegisterApiControllers(ass); bulider.RegisterControllers(ass); //5.0 告诉auto发出容器创建者创建一个auto的正真容器对象 var container = bulider.Build(); //6.0 将当前的autofac容器对象存入全局缓存中 CacheMgr.SetData(Keys.autofaccontainer, container); //6.0 告诉MVC将DefaultControllerFactory替换成autofac中的控制器创建工厂 //将来所有的接口使用container去进行传递 config.DependencyResolver = new AutofacWebApiDependencyResolver(container); DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
public object SysEnergyAnalsys(DateTime currtime, DateTime begtime) { //找到每个空压站的最大和最小流量 var res = dal.QueryWhere(d => d.DateTime >= begtime && d.DateTime <= currtime).GroupBy(g => g.StationID).Select(s => new { Maxvalue = s.Max(i => i.Main_Q), Minvalue = s.Min(i => i.Main_Q), sta = s.Key }).ToList(); //获取缓存对象,任何阈值设定界面值的修改,都要缓存当前 List <BB_Threshold> cacheThre = CacheMgr.GetData <List <BB_Threshold> >("threshold"); //判断是否有缓存存在,不存在重新设置 if (cacheThre == null) { List <BB_Threshold> threshold = thresholdal.QueryWhere().ToList(); CacheMgr.SetData("threshold", threshold); cacheThre = threshold; } //目标压力 decimal setPress = (decimal)cacheThre.Where(x => x.Name.Equals("管网压力设定")).FirstOrDefault().CurrentValue; //设定间隔 decimal intval = (decimal)cacheThre.Where(x => x.Name.Equals("管网压力设定间隔")).FirstOrDefault().CurrentValue; List <List <decimal> > dvalue = new List <List <decimal> >(); List <List <decimal> > setdvalue = new List <List <decimal> >(); foreach (var item in res) { decimal max = (decimal)item.Maxvalue / 15000; int imax = (int)max + 1; //最大开机数 decimal min = (decimal)item.Minvalue / 15000; int imin = (int)min; //最小开机数 if (item.sta == "S004") { if (imax > 7) { imax = 7; } } else { if (imax > 6) { imax = 6; } } int n = imax - imin; //开机数差 List <decimal> press = new List <decimal>(); //压力设定集合 List <decimal> value = new List <decimal>(); //空压机集合 decimal countvalue = setPress + intval * n; //基础压力设定值 #region 空压机填充 for (int i = 0; i < imin; i++) { value.Add(countvalue); value.Add(0); value.Add(0); value.Add(0); } for (int i = 0; i < n; i++) { if (i == 0) { value.Add(0); value.Add(countvalue - intval * (i + 1)); value.Add(0); value.Add(0); } else if (i == 1) { value.Add(0); value.Add(0); value.Add(countvalue - intval * (i + 1)); value.Add(0); } else { for (int j = 0; j < n - 2; j++) { value.Add(0); value.Add(0); value.Add(0); value.Add(countvalue - intval * (i + 1)); } } } #endregion press.Add(countvalue); //压力设定填充 for (int i = 0; i < n; i++) { press.Add((countvalue - intval * (i + 1))); } if (press.Count() < 4) { press.Add(0); } setdvalue.Add(press); if (item.sta == "S004") { if (value.Count() < 28) { int vcount = value.Count(); decimal one = value[vcount - 4]; decimal two = value[vcount - 3]; decimal three = value[vcount - 2]; decimal four = value[vcount - 1]; for (int i = 0; i < (28 - vcount) / 4; i++) { value.Add(one); value.Add(two); value.Add(three); value.Add(four); } } } else { if (value.Count() < 24) { int vcount = value.Count(); decimal one = value[vcount - 4]; decimal two = value[vcount - 3]; decimal three = value[vcount - 2]; decimal four = value[vcount - 1]; for (int i = 0; i < (24 - vcount) / 4; i++) { value.Add(one); value.Add(two); value.Add(three); value.Add(four); } } } dvalue.Add(value); } var tranres = new { disarr = setdvalue, arr = dvalue }; return(tranres); }