当前位置: 首页 > news >正文

哪个网站可以做问卷泰州网站建设公司哪家好

哪个网站可以做问卷,泰州网站建设公司哪家好,电子商务平台开发建设,花生壳动态域名做网站闲来没事#xff0c;自己就想着根据反射可以自己写一个简易的IOC组件。IOC组件说白了就是根据反射实例化对应的接口。废话不多说#xff0c;开始说说我的解决方案。1、项目结构图#xff1a;IOCTest为web MVC项目。Common 通过配置文件实例化对应的接口IBLL定义的接口BLL实现… 闲来没事自己就想着根据反射可以自己写一个简易的IOC组件。IOC组件说白了就是根据反射实例化对应的接口。废话不多说开始说说我的解决方案。1、项目结构图IOCTest为web MVC项目。Common 通过配置文件实例化对应的接口IBLL定义的接口BLL实现接口2、引用IOCTest项目引用IBLL、Common项目不能引用BLL项目这样就使IOCTest项目只依赖接口。BLL项目引用IBLL并实现接口修改BLL项目dll生成路径使其DLL生成到IOCTest项目的Bin目录下如下图设置 3、下面我们来看具体的实现(1)在IBLL层的IHelloWord.cs类中我们定义一个接口代码如下using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace IBLL {public interface IHelloWord{string SayHello(string Name);} } br (2)BLL层实现接口‍using System; using System.Collections.Generic; using System.Linq; using System.Text; using IBLL;namespace BLL {public class HelloWord:IHelloWord{#region IHelloWord 成员public string SayHello(string Name){return Hello_Name;}#endregion}} (3)在IOCTest 项目的根目录Web.config下做如下配置(把HelloWord和IHelloWord对应起来)appSettingsadd keyIBLL.IHelloWord valueBLL,BLL.HelloWord//appSettings说明  key值为接口的全称(命名空间类名)value值为实现接口的类两部分组成逗号前面为生成的dll名称逗号后面为类名全称(命名空间类名)。 (4)Common 项目的IOCReflecter.cs类根据配置文件获取对应接口的实例化对象代码实现如下using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; using System.Reflection; using System.Configuration;namespace Common {public class IOCReflecter{private static Hashtable s_typenull;static IOCReflecter(){s_type new Hashtable();}public static T CreateIntanceT(){Type ttypeof(T);//keyType type s_type[t] as Type;//valueif (type null){string[] AssemblyInfos ConfigurationManager.AppSettings[t.FullName].Split(,);type Assembly.Load(AssemblyInfos[0]).GetType(AssemblyInfos[1]);s_type.Add(t, type);}return (T)CreateObject(type) ;}/// summary/// 根据typeName获取Type对象/// /summary/// param nametypeName/param/// returns/returnspublic static Type GetType(string typeName){if (string.IsNullOrWhiteSpace(typeName)){return null;}return Type.GetType(typeName);}/// summary/// 获取对象/// /summary/// param namet/param/// returns/returnsprivate static object CreateObject(Type t){if (t null){return null;}//查找没有参数的构造函数//如果需要初始化带参数的构造函数 t.GetConstructors() 获取所有的构造函数 it.GetParameters()获取构造函数所有的参数ConstructorInfo NonParameterConstructors t.GetConstructors().Where(itit.GetParameters().Length0).FirstOrDefault();if (NonParameterConstructors null){throw new Exception( t.FullName必须有一个无参数或默认的构造函数);}//调用数构造函数创建对象return t.InvokeMember(null, BindingFlags.CreateInstance, null, null, null);}} } (5)测试在IOCTest项目Controllers中添加HomeController.cs文件代码如下using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using IBLL; using Common;namespace IOCTest.Controllers {public class HomeController : Controller{//// GET: /Home/public ActionResult Index(){//获取实例化对象IHelloWord hello IOCReflecter.CreateIntanceIHelloWord();ViewBag.Message hello.SayHello(eric);return View();}} } {ViewBag.Title Index; }h2ViewBag.Message /h2 最后上一张截图到此结束
http://www.pierceye.com/news/54007/

相关文章:

  • php精品网站建设物业公司网站模板
  • 环保部网站建设项目重大变动wordpress点击折叠展开内容
  • 建站需求建设网站市场细分
  • Ul设计网站网站如何做美工
  • 门户网站安全建设方案国家医保服务平台
  • 汽车网站建设论坛网站建设要多少钱品牌
  • 做网站默认城市网络营销有哪些岗位
  • 网站开发基本要求公司免费网站模板
  • 一条龙建站多少钱wordpress主题很慢
  • 做网站设计难吗国外机械做的好的网站
  • 网站建设流程步骤腾讯云重装wordpress
  • 校园网站建设简介有限公司和公司哪个好
  • 东莞网站优化关键词费用建设网络平台 英语
  • 美食网站网页设计代码吕梁seo排名
  • php网站后台怎么登陆企业手机端网站设计模板
  • 简单的网站开发模板锦州做网站
  • 北京市中关村有哪家可以做网站维护关键词推广效果
  • 柯城网站建设wordpress cdn
  • 做网站多少钱?杭州模板建站哪家好
  • 深圳电商网络网站建设网站建设_网站制作公司_捷创
  • 网站开发的项目总结网站设计的难点
  • 网站怎么换空间商做多个网站 买vps
  • 网站推广的定义及方法wordpress erphpdowns
  • 网站建设首选建站系统沧州开发网站多少钱
  • php做的网站首页是什么文件夹seo网站推广工作内容
  • 做网站沈阳本地做我男朋友好不好网站
  • 电商平台站内推广有哪些棉花数据检验与加工平台
  • 国内网站做得好的公司网站建设推广好处
  • 建设局网站打不开是什么原因不用建网站怎么做淘宝客
  • 网站开发环境有哪些php模版网站建设步骤详解