Ioc-StructureMap
来源:互联网 发布:邓肯生涯场均数据 编辑:程序博客网 时间:2024/05/16 16:11
1. Global.asax
protected void Application_Start() { BootStrapper.ConfigureStructureMap(); }
2.BootStrapper
public class BootStrapper { public static void ConfigureStructureMap() { // Initialize the registry ObjectFactory.Initialize(x => { x.AddRegistry<ModelRegistry>(); }); } public class ModelRegistry : Registry { public ModelRegistry() { ForRequestedType<IGetTotalElectricGrid>().TheDefault.Is.OfConcreteType<GetTotalElectricGridDPI>(); ForRequestedType<IGetAirSystemElectric>().TheDefault.Is.OfConcreteType<GetAirSystemElectricDPI>(); ForRequestedType<IGetItemsElectric>().TheDefault.Is.OfConcreteType<GetItemsElectricDPI>(); ForRequestedType<IGetDataByDay>().TheDefault.Is.OfConcreteType<GetDataByDayDIP>(); ForRequestedType<IGetDataByWeek>().TheDefault.Is.OfConcreteType<GetDataByWeekDPI>(); ForRequestedType<IGetDataByMonth>().TheDefault.Is.OfConcreteType<GetDataByMonthDPI>(); ForRequestedType<IGetDataByYear>().TheDefault.Is.OfConcreteType<GetDataByYearDPI>(); } } }
3.HomeController
[HttpPost] public string GetChartIt(FormCollection fc) { HomePageClientControl homePageClientControl = ObjectFactory.GetInstance<HomePageClientControl>(); return homePageClientControl.GetData(fc["data"].ToString()); //return HomePageClientControl.Instance().GetData(fc["data"].ToString()); }
4.IGetDataByDay
public interface IGetDataByDay { StringBuilder GetDataByDay(string data); }
5.GetItemsElectricDPI
public class GetItemsElectricDPI : IGetItemsElectric { public StringBuilder GetItemsElectric(string time) { string[] str = ClientControl.GetChartDataType.GetTimeByType.GetTimeByTypeTime(time); DataTable dt = null; if (time == "日") { dt = HomePageDataControl.Instance().GetTypeElectric(str[0], str[1]); } else//周,月,年 { dt = HomePageDataControl.Instance().GetTypeElectricByDay(str[0], str[1]); } StringBuilder json = new StringBuilder(); json.Append("{ 'chart': { 'caption': '分项用电比例', 'numberSuffix': '(kwh)', 'baseFont':'微软雅黑','baseFontSize':'12'}, 'data': [ " + "{ 'label': '照明插座', 'value': '" + dt.Rows[0][0].ToString() + "' }, " + "{ 'label': '空调', 'value': '" + dt.Rows[1][0].ToString() + "' }, " + "{ 'label': '动力', 'value': '" + dt.Rows[2][0].ToString() + "' }, " + "{ 'label': '特殊', 'value': '" + dt.Rows[3][0].ToString() + "' }]}"); json = json.Replace("'", "\""); return json; } }
6. HomePageClientControl
private readonly IGetTotalElectricGrid _getTotalElectricGrid; private readonly IGetAirSystemElectric _getAirSystemElectric; private readonly IGetItemsElectric _getItemsElectric; private readonly IGetDataByDay _getDataByDay; private readonly IGetDataByWeek _getDataByWeek; private readonly IGetDataByMonth _getDataByMonth; private readonly IGetDataByYear _getDataByYear; public HomePageClientControl(IGetTotalElectricGrid getTotalElectricGrid, IGetAirSystemElectric getAirSystemElectric, IGetItemsElectric getItemsElectric, IGetDataByDay getDataByDay, IGetDataByWeek getDataByWeek, IGetDataByMonth getDataByMonth, IGetDataByYear getDataByYear) { this._getTotalElectricGrid = getTotalElectricGrid; this._getAirSystemElectric = getAirSystemElectric; this._getItemsElectric = getItemsElectric; this._getDataByDay = getDataByDay; this._getDataByWeek = getDataByWeek; this._getDataByMonth = getDataByMonth; this._getDataByYear = getDataByYear; } public string GetData(string data) { StringBuilder json = new StringBuilder(); //json.Append(GetChartData.GetTotalElectricGrid(data)); json.Append(this._getTotalElectricGrid.GetTotalElectricGrid(data));json.Append("&&"); //json.Append(GetChartData.GetAirSystemElectric(data)); json.Append(this._getAirSystemElectric.GetAirSystemElectric(data));json.Append("&&"); //json.Append(GetChartData.GetItemsElectric(data)); json.Append(this._getItemsElectric.GetItemsElectric(data));json.Append("&&"); //json.Append(GetChartData.GetUnitAreaElectric(data)); //json.Append("&&"); //json.Append(GetChartData.GetPerAverage(data)); //json.Append("&&"); //json.Append(GetChartData.GetTotalEnergy(data)); //json.Append("&&"); //json.Append(GetChartData.GetTotalElectric(data, "")); //json.Append("&&"); //json.Append(GetChartData.GetTotalWater(data, "")); //json.Append("&&"); //json.Append(GetChartData.GetTotalGas(data)); if (data.Equals("日")) { json.Append(this._getDataByDay.GetDataByDay(data)); } if (data.Equals("周")) { json.Append(this._getDataByWeek.GetDataByWeek(data)); } if (data.Equals("月")) { json.Append(this._getDataByMonth.GetDataByMonth(data)); } if (data.Equals("年")) { json.Append(this._getDataByYear.GetDataByYear(data)); } return json.ToString(); }
- Ioc-StructureMap
- 轻量级IOC框架:StructureMap
- [IOC] StructureMap的疑惑。
- [IOC] StructureMap的疑惑
- StructureMap 轻量IOC框架
- 使用StructureMap和Autofac等Ioc容器
- StructureMap
- IOC框架Castle Windsor 微软企业库中的Unity Spring.NET StructureMap Ninject性能比较
- StructureMap使用说明
- StructureMap极速上手指南(翻译)
- StructureMap+EF+Linq搭建MVC框架
- IoC
- IoC
- Ioc
- ioc
- Ioc
- ioc
- ioc
- DULO:一种利用时间和空间局部性的高效缓存置换策略
- Java]读取文件方法
- linux 常用指令
- 下拉框
- 在Windows 2008安装SQL 2008
- Ioc-StructureMap
- TCP3次握手连接协议和4次握手断开连接协议
- C/C++ 误区一:void main()
- Struts1 ActionForm 工作原理
- 4G无线套餐流量少的可怜,准备好支付4G的庞大账单吧
- 博弈练习&总结
- jdk1.5新特性 ConcurrentHashMap
- μC/OS之OSTaskCreate()
- [ARM笔记]嵌入式Linux中断处理程序架构