轻量级国际奥委会容器IOCFactory发布。

  

这是我的第三篇讨论奥委会工厂的文章了,貌似我已经跟国际奥委会工厂杠上了。轻量级国际奥委会容器IOCFactory发布。

前两篇是说的造轮子的过程。貌似没什么人感兴趣,那这次就直接发布轮子吧。


轻量级国际奥委会容器IOCFactory发布。

上的图是我的容器与微软的企业库统一的性能比较。

可以看见。效率是微软企业库的6倍。

使用依赖注入模式效率也比微软企业库要快。


目前支持以下几种模式对象的创建

普通模式,

单例模式,

依赖注入模式,

装饰模式,

以及单例注入模式


5种模式的获取方式类似都是采用

Factory.Get([主要])的方式进行获取。


但是注册有所不同。


factory.Regist (IOCFactoryModel.InstType.Normal);//普通模式   factory.Regist (InstType.DI);//依赖注入模式   factory.Regist (InstType.Singleton);//单例模式   factory.RegistDecorate (“catDog”、“猫”);//装饰者模式   factory.Regist (InstType.DISingleton)//单例注入模式


下面是使用的示例代码

名称空间IOCFactoryUnitTest
  {
  公共接口的动物
  {
  字符串Hawl ();
  }
  公共接口的玩具
  {
  字符串();
  }
  公共类球:玩具
  {
  公共字符串打()
  {
  返回“辊和辊”;
  }
  }
  公共类狗:动物
  {
  公共字符串Hawl ()
  {
  var returnValue=" https://www.yisu.com/zixun/wang汪汪”;
  返回returnValue;
  }
  }
  公共类猫:动物
  {
  公共字符串Hawl ()
  {
  var returnValue=" https://www.yisu.com/zixun/miao苗苗”;
  返回returnValue;
  }
  }
  公共类CatDog:动物
  {
  私人动物toDecorate;
  公共CatDog(动物toDecorate)
  {
  这一点。toDecorate=toDecorate;
  }
  公共字符串Hawl ()
  {
  var returnValue=https://www.yisu.com/zixun/toDecorate.Hawl ();
  returnValue +=巴敉敉簟?
  返回returnValue;
  }
  }
  公共类MachineCatDog:动物
  {
  私人动物toDecorate;
  公共MachineCatDog(动物toDecorate)
  {
  这一点。toDecorate=toDecorate;
  }
  公共字符串Hawl ()
  {
  var returnValue=https://www.yisu.com/zixun/toDecorate.Hawl ();
  returnValue +=班培培拧?
  返回returnValue;
  }
  }
  公共类SingleTonTest:动物
  {
  私人SingleTonTest () {}
  公共字符串Hawl ()
  {
  .ToString返回this.GetHashCode () ();
  }
  }
  公共类说
  {
  动物的动物;
  玩具玩具;
  公开说(动物动物,玩具玩具)
  {
  这一点。动物=动物;
  这一点。玩具=玩具;
  }
  公共字符串测试()
  {
  返回animal.Hawl () + this.toy.Play ();
  }
  }
  (TestClass)
  公开课IOCFactoryTest
  {
  [ClassInitialize ()]
  公共静态孔隙Init(和TestContext上下文)
  {
  工厂工厂=Factory.GetInst ();
  factory.Regist<动物,Cat>(“猫”,InstType.Normal);
  factory.Regist<动物,Dog>(“狗”,InstType.Normal);
  factory.Regist<动物,SingleTonTest> (InstType.Singleton);
  factory.RegistDecorate<动物,CatDog> (“catDog”、“猫”);
  factory.RegistDecorate<动物,MachineCatDog> (“catDog”、“猫”);
  Ball> factory.Regist<玩具;(InstType.Normal);
  factory.Regist<说,DITest> (InstType.DISingleton);
  }
  (TestCleanup)
  公共空间清理()
  {
  }
  (TestMethod)
  公共空间NormalInstTest ()
  {
  工厂工厂=Factory.GetInst ();
  var=新狗();
  var狗=factory.Get(“狗”);
  result.Hawl Assert.AreEqual (dog.Hawl () ());
  猫var=factory.Get(“猫”);
  result.Hawl Assert.AreNotEqual (cat.Hawl () ());
  }
  (TestMethod)
  公共空间SingleInstTest ()
  {
  工厂工厂=Factory.GetInst ();
  var其中obj1=factory.Get ();
  var methoda=factory.Get ();
  断言。AreEqual(其中obj1 methoda);
  }
  (TestMethod)
  公共空间DecorateInstTest ()
  {
  工厂工厂=Factory.GetInst ();
  var狗=factory.Get(“狗”);
  猫var=factory.Get(“猫”);
  var catDog=factory.Get

轻量级国际奥委会容器IOCFactory发布。