国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

初入Spring.net

2019-11-14 16:49:46
字體:
來源:轉載
供稿:網友

IOC:Inversion Of Control

控制翻轉:就是創建對象的權利由開發人員自己控制,轉換到了由容器來控制

我用的是winform里的一個按鍵來觸發的

首先要引入兩個SPRing.net的dll文件Common.Logging.dll 和Spring.Core.dll

    private void button1_Click(object sender, EventArgs e)        {                        IapplicationContext ctx = ContextRegistry.GetContext();            UserInfoService userInfo = (UserInfoService)ctx.GetObject("UserInfoService");            userInfo.Show();        }
    public class UserInfoService    {        public UserInfo user { get; set; }
    //構造函數
public UserInfoService(int age) { Age = age; } public int Age { get; set; } public string serverName { get; set; } public void Show() { Console.WriteLine("OK2------"+serverName); Console.WriteLine("Age=" + Age); Console.WriteLine("User=" + user.uName); } }}

//user類型
namespace
SpringDemo{ public class UserInfo { public string uName { get; set; } }}

之后就直接在app.config里注入代碼就可以了

<?xml version="1.0" encoding="utf-8" ?><configuration>  <configSections>    <sectionGroup name="spring">      <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>      <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />    </sectionGroup>  </configSections>  <spring>    <context>      <resource uri="config://spring/objects"/>      <resource uri="file://Servicess.xml"/>    </context>    <objects xmlns="http://www.springframework.net">      <description>An  example that demonstrates simple IoC features.</description>      <object name="UserInfoService" type="SpringDemo.UserInfoService, SpringDemo ">        <constructor-arg name="age" value="18"/>//--------構造函數注入        <property name="serverName" value="yang"/>//------------屬性注入        <property name="user" ref="UserInfo"/>              </object>      <object name="UserInfo" type="SpringDemo.UserInfo, SpringDemo ">//-----user類型的注入        <property name="uName" value="yang2"/>      </object>    </objects>  </spring></configuration>

然后調試就完美輸出了

OK2---------yang

Age=18

User=yang2

 

從現在開始一點點進步


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 饶河县| 石狮市| 融水| 景宁| 凌海市| 上饶县| 清苑县| 清水县| 旌德县| 西藏| 长葛市| 乌兰浩特市| 称多县| 封开县| 渝北区| 那曲县| 嵩明县| 崇左市| 东莞市| 厦门市| 泽州县| 刚察县| 石河子市| 外汇| 横峰县| 临高县| 平南县| 乌兰察布市| 宜兰市| 莆田市| 高邮市| 潜江市| 松滋市| 吴忠市| 错那县| 广州市| 琼中| 内丘县| 南召县| 泰宁县| 射洪县|