乡下人产国偷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

      創(chuàng)建對象一般有3中方式:1.構(gòu)造器創(chuàng)建。2.靜態(tài)工廠創(chuàng)建。3.實(shí)例工廠創(chuàng)建。

      多數(shù)情況下,容器會根據(jù)對象定義中的type屬性值去直接調(diào)用響應(yīng)類型的某個(gè)構(gòu)造器。另外,容器也可以調(diào)用工廠方法來創(chuàng)建對象,這時(shí)type屬性的值就應(yīng)該是包含工廠方法的類型(注:而不是要創(chuàng)建的類型,但通過該對象定義的名稱獲取的是由工廠方法所創(chuàng)建的對象)。工廠方法的產(chǎn)生對象可以是工廠方法所在的類型,也可以是其他類型(注:很多情況下工廠方法位于單獨(dú)的類型中),這無關(guān)緊要。

      一、通過構(gòu)造器創(chuàng)建對象、

      通過構(gòu)造器創(chuàng)建隊(duì)形需要滿足這幾個(gè)條件:1.指明對象類型type=”類全名,程序集名”

      2.有一個(gè)無參的構(gòu)造函數(shù)或者默認(rèn)構(gòu)造函數(shù)。

      1. <!--構(gòu)造器-->
      2. <object id="PersonDao" type="Dao.PersonDao, Dao">
      3. </object>
      1. /// <summary>
      2. /// 構(gòu)造器創(chuàng)建
      3. /// </summary>
      4. static void CreateByConstructor()
      5. {
      6. string[] XMLFiles = new string[]
      7. {
      8. "assembly://CreateObjects/CreateObjects/Objects.xml"
      9. };
      10. IApplicationContext context = new XmlApplicationContext(XMLFiles);
      11. IObjectFactory factory = (IObjectFactory)context;
      12. Console.Write(factory.GetObject("PersonDao").ToString());
      13. }

      嵌套類型對象的創(chuàng)建需要“+”號來連接被嵌套的類型。如果在PersonDao中嵌套了類型Person

      1. <!--嵌套類型-->
      2. <object id="Person" type="Dao.PersonDao+Person, Dao">
      3. </object>
      1. /// <summary>
      2. /// 嵌套類型創(chuàng)建
      3. /// </summary>
      4. static void CreateNested()
      5. {
      6. string[] XMLFiles = new string[]
      7. {
      8. "assembly://CreateObjects/CreateObjects/Objects.xml"
      9. };
      10. IApplicationContext context = new XmlApplicationContext(XMLFiles);
      11. IObjectFactory factory = (IObjectFactory)context;
      12. Console.Write(factory.GetObject("Person").ToString());
      13. }

      二、靜態(tài)工廠創(chuàng)建

      使用靜態(tài)工廠創(chuàng)建對象需要配置factory-mothod屬性

      1. <!--靜態(tài)工廠-->
      2. <object id="StaticObjectsFactory" type="DaoFactory.DataAccess, DaoFactory" factory-method="CreatePersonDao">
      3. </object>
      1. /// <summary>
      2. /// 靜態(tài)工廠創(chuàng)建
      3. /// </summary>
      4. static void CreateByStaticFactory()
      5. {
      6. string[] XMLFiles = new string[]
      7. {
      8. "assembly://CreateObjects/CreateObjects/Objects.xml"
      9. };
      10. IApplicationContext context = new XmlApplicationContext(XMLFiles);
      11. IObjectFactory factory = (IObjectFactory)context;
      12. Console.Write(factory.GetObject("StaticObjectsFactory").ToString());
      13. }

      三、使用實(shí)例工廠創(chuàng)建對象

      使用實(shí)例工廠創(chuàng)建隊(duì)形需要先定義一個(gè)工廠,然后設(shè)factory-object和factory-method屬性,且滿足實(shí)例工廠方法所在的對象必須也要配置在同一容器(或父容器)中 和 對象定義就不能包含type屬性

      1. <!--實(shí)例工廠-->
      2. <!--工廠-->
      3. <object id="instanceObjectsFactory" type="DaoFactory.DataAccess, DaoFactory">
      4. </object>
      5. <!--創(chuàng)建的對象-->
      6. <object id="instancePersonDao" factory-method="CreateInstance" factory-object="instanceObjectsFactory">
      7. </object>
      1. /// <summary>
      2. /// 實(shí)例工廠創(chuàng)建
      3. /// </summary>
      4. static void CreateByInstanceFactory()
      5. {
      6. string[] xmlFiles = new string[]
      7. {
      8. "assembly://CreateObjects/CreateObjects/Objects.xml"
      9. };
      10. IApplicationContext context = new XmlApplicationContext(xmlFiles);
      11. IObjectFactory factory = (IObjectFactory)context;
      12. Console.WriteLine(factory.GetObject("instancePersonDao").ToString());
      13. }

      四、泛型類型的創(chuàng)建

      泛型類型的創(chuàng)建比較類型于以上幾種創(chuàng)建,可以有通過構(gòu)造器創(chuàng)建,還可以通過靜態(tài)或者工廠創(chuàng)建,但是設(shè)置type屬性的時(shí)候要注意:左尖括號<要替換成字符串”<”,因?yàn)樵赬ML中左尖括號會被認(rèn)為是小于號。

      1. <!--創(chuàng)建泛型-->
      2. <object id="genericClass" type="Dao.GenericClass<int>, Dao" >
      3. </object>    
      1. /// <summary>
      2. /// 泛型創(chuàng)建
      3. /// </summary>
      4. static void CreateByGenericClass()
      5. {
      6. string[] xmlFiles = new string[]
      7. {
      8. "assembly://CreateObjects/CreateObjects/Objects.xml"
      9. };
      10. IApplicationContext context = new XmlApplicationContext(xmlFiles);
      11. IObjectFactory factory = (IObjectFactory)context;
      12. Console.WriteLine(factory.GetObject("genericClass").ToString());
      13. }

      代碼連接:https://download.csdn.net/download/wjgwrr/10429544

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

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多