zoukankan      html  css  js  c++  java
  • spring.net的基本搭建

    这几天在学C#,感觉还是需要一个控制反转的框架,正好Spirng也有.net版的,看着API搭建一个

    大致目录是这样的,我们在APP.CONFIG里面配好xml文件的地址,这个APP.CONFIG就相当于是JAVA中的web.xml,object.xml相当于java框架里的applicationcontext.xml

    1. <?xml version="1.0" encoding="utf-8" ?>  
    2. <configuration>  
    3.   
    4.   <configSections>  
    5.     <sectionGroup name="spring">  
    6.       <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />  
    7.       <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />  
    8.     </sectionGroup>  
    9.   </configSections>  
    10.   
    11.   <spring>  
    12.   
    13.     <context>  
    14.       <resource uri="assembly://FirstSpringNetApp/FirstSpringNetApp/Objects.xml"/>  
    15.       <resource uri="config://spring/objects" />  
    16.     </context>  
    17.     <objects xmlns="http://www.springframework.net"/>  
    18.     <!--必要-->  
    19.   </spring>  
    20.   
    21. </configuration>  


     

    第二个OBJECT.XML

    1. <?xml version="1.0" encoding="utf-8" ?>  
    2.   
    3. <objects xmlns="http://www.springframework.net"  
    4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
    5.     xsi:schemaLocation="http://www.springframework.net  
    6.         http://www.springframework.net/xsd/spring-objects.xsd">  
    7.   
    8.   <object id="PersonDao" type="FirstSpringNetApp.PersonDao, FirstSpringNetApp" />  
    9.     
    10. </objects>  

    然后就可以调用里面配好的对象了

    1. using System;  
    2. using System.Collections.Generic;  
    3. using System.Linq;  
    4. using System.Text;  
    5. using Spring.Context;  
    6. using Spring.Context.Support;  
    7. using Spring.Core.IO;  
    8. using Spring.Objects.Factory;  
    9. using Spring.Objects.Factory.Xml;  
    10.   
    11. namespace FirstSpringNetApp  
    12. {  
    13.     class Program  
    14.     {  
    15.         static void Main(string[] args)  
    16.         {  
    17.             AppRegistry();  
    18.             Console.ReadLine();  
    19.         }  
    20.   
    21.         static void AppRegistry()  
    22.         {  
    23.             IApplicationContext ctx = ContextRegistry.GetContext();  
    24.             Console.WriteLine(ctx.GetObject("PersonDao").ToString());  
    25.         }  
    26.     }  
    27. }  


     


     

  • 相关阅读:
    微服务下,使用ELK做日志收集及分析
    Spring boot下,集成任务调度中心(XXL-JOB)
    使用mysqldump 导出数据时的常用选项
    MySQL 批量insert 、单条insert
    分享一个 电子书下载网站 支持 ebook pdf azw3 epub mobi
    稀疏数组
    LaTeX 交叉引用系统简介
    服务器jupyter配置与ssh远程登录
    postgresql中终止正在执行的SQL语句
    Python 个人笔记(一)
  • 原文地址:https://www.cnblogs.com/tiancai/p/4556002.html
Copyright © 2011-2022 走看看