乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Spring.NET教程(五)

       黃金屋1 2019-05-26

      Spring.NET教程(五)——容器中對象的作用域(基礎(chǔ)篇)

      2018年05月23日 10:43:41 Wang Jianguo 閱讀數(shù):84

              容器中象的部署分兩種方式:singleton和非singleton(javaprototype)。里的singleton指的是例模式,就是當(dāng)一個象被定義為singleton,容器中就只會有一個共享的例,任何候通id該對象都會返回個共享例的引用(也就是說這象只會被創(chuàng)建一次)。當(dāng)使用非singleton,或者原型模式布署,每次象都會創(chuàng)建新的例。在某些合,如果需要每個用返回獨的用戶對象或其它象,非singlton布署模式就比理想。Spring.NET認(rèn)為singleton模式。每次調(diào)GetObject方法得到的都是同例;當(dāng)singleton="false",每次調(diào)GetObject方法得到的是不同的

      1. <?xml version="1.0" encoding="utf-8" ?>
      2. <objects xmlns="http://www.">
      3. <!--單例模式-->
      4. <object id="personDao" type="SpringNetScopes.PersonDao, SpringNetScopes"/>
      5. <!--非單例模式-->
      6. <object id="person" type="SpringNetScopes.Person, SpringNetScopes" singleton="false" />
      7. <!--調(diào)用時加載-->
      8. <object id="personServer" type="SpringNetScopes.PersonServer, SpringNetScopes" lazy-init="true"/>
      9. </objects>
      1. namespace SpringNetScopes
      2. {
      3. public class PersonDao : IPersonDao
      4. {
      5. public PersonDao()
      6. {
      7. Console.WriteLine("PersonDao被實例");
      8. }
      9. public override string ToString()
      10. {
      11. return "我是PersonDao";
      12. }
      13. ~PersonDao()
      14. {
      15. Console.WriteLine("PersonDao被銷毀");
      16. }
      17. public void Save()
      18. {
      19. Console.WriteLine("保存 Person");
      20. }
      21. }
      22. public class Person
      23. {
      24. public Person()
      25. {
      26. Console.WriteLine("Person被實例");
      27. }
      28. public override string ToString()
      29. {
      30. return "我是Person";
      31. }
      32. ~Person()
      33. {
      34. Console.WriteLine("Person被銷毀");
      35. }
      36. }
      37. public class PersonServer
      38. {
      39. public PersonServer()
      40. {
      41. Console.WriteLine("PersonServer被實例");
      42. }
      43. public override string ToString()
      44. {
      45. return "我是PersonServer";
      46. }
      47. ~PersonServer()
      48. {
      49. Console.WriteLine("PersonServer被銷毀");
      50. }
      51. }
      52. }
      53. [TestMethod]
      54. public void CreateWithSingleton()
      55. {
      56. string[] xmlFiles = new string[]
      57. {
      58. "assembly://SpringNetScopes/SpringNetScopes/Objects.xml"
      59. };
      60. IApplicationContext context = new XmlApplicationContext(xmlFiles);
      61. IObjectFactory factory = (IObjectFactory)context;
      62. object obj1 = factory.GetObject("personDao");
      63. object obj2 = factory.GetObject("personDao");
      64. Assert.AreEqual(obj1, obj2);
      65. }
      66. [TestMethod]
      67. public void CreateWithOutSingleton()
      68. {
      69. string[] xmlFiles = new string[]
      70. {
      71. "assembly://SpringNetScopes/SpringNetScopes/Objects.xml"
      72. };
      73. IApplicationContext context = new XmlApplicationContext(xmlFiles);
      74. IObjectFactory factory = (IObjectFactory)context;
      75. object obj1 = factory.GetObject("person");
      76. object obj2 = factory.GetObject("person");
      77. Assert.AreNotEqual(obj1, obj2);
      78. }
      79. [TestMethod]
      80. public void CreateWithLazy()
      81. {
      82. string[] xmlFiles = new string[]
      83. {
      84. "assembly://SpringNetScopes/SpringNetScopes/Objects.xml"
      85. };
      86. IApplicationContext context = new XmlApplicationContext(xmlFiles);
      87. IObjectFactory factory = (IObjectFactory)context;
      88. object dao = factory.GetObject("personDao");
      89. Console.WriteLine(dao.ToString());
      90. object server = factory.GetObject("personServer");
      91. Console.WriteLine(server.ToString());
      92. }

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多