• Install Spring.NET.exe
  • Create a console application, and reference Spring.Core.dll.
  • Add App.config to project, the content is as follows
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="spring">
<section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core"/>
</sectionGroup>
</configSections>
<spring>
<context>
<resource uri="spring.xml.config"/>
</context>
</spring>
</configuration>
  • Program.cs as follows
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
IApplicationContext context = ContextRegistry.GetContext(); Hello hello = (Hello)context.GetObject("hello"); System.Console.Out.WriteLine(hello.HelloWorld);
System.Console.In.Read();
}
} class Hello
{
private string helloworld; public string HelloWorld
{
get { return this.helloworld; }
set { this.helloworld = value; }
}
}
}
  • Add spring.xml.config to project (set Copy always to output directory), the content is as follows

主程序中调用context.GetObject并传入"hello"参数,就会在这里查找相应的类,以其来创建实例,并根据配置给此实例的属性HelloWorld赋值。

<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net">
<object id="hello" type="ConsoleApplication5.Hello">
<property name="HelloWorld" value="Hello!Welcome to Spring.Net World!"/>
</object>
</objects>
  • Run application.
  • Spring.net的核心思想是Ioc,依赖文件中的配置来决定程序的执行走向。

Using Spring.net in console application的更多相关文章

  1. Spring boot 全局配置文件application.properties

    #更改Tomcat端口号 server.port=8090 #修改进入DispatcherServlet的规则为:*.htmlserver.servlet-path=*.html#这里要注意高版本的s ...

  2. 如何将Console application的Program函数变成支持async的?

    如何将Console application的Program函数变成支持async的?   class Program { static void Main(string[] args) { Task ...

  3. win32 console application 如何修改图标?

    win32 console application ,不要看这名字高端大气上档次,让你摸不着头脑,其实他就是我们最先学习c语言那种黑色窗口的东西......话说他怎么修改图标呢?第一种方法是:右键-〉 ...

  4. Hello World 之 控制台版本(Console Application)

    原文:Hello World 之 控制台版本(Console Application) 先来介绍下Hello, World   "Hello, World"程序指的是只在计算机屏幕 ...

  5. RESTful Console Application

    RESTful Console Application Introduction Inspirited by RESTFul architecture, A console application t ...

  6. spring boot 无法读取application.properties问题

    spring boot 无法读取application.properties问题 https://bbs.csdn.net/topics/392374488 Spring Boot 之注解@Compo ...

  7. Fix Visual Studio 2013 Razor CSHTML Intellisense in Class Library or Console Application

    https://mhusseini.wordpress.com/2015/02/05/fix-visual-studio-2013-razor-cshtml-intellisense-in-class ...

  8. C# 控制台程序(Console Application )启动后隐藏

    背景 前段时间给项目编写了数据适配器,读取其他系统的数据后推送到MQ上,我们的系统通过订阅MQ的方式来获取.由于其他系统支持C#编程,且为了一时方便,选择了C#的控制台程序. 最近用户在使用中,总是不 ...

  9. .NET 如何隐藏Console Application的窗口

    1)创建Console Application工程 2)修改Output type 为Windows Application即可

随机推荐

  1. 10.16JS日记

    1.parseint() 2.parsefloat() 这两个单词运行的时候遇到第一个非数字就结束了 3.var a="hello word"  a这个变量为字符串,每一个字母为字 ...

  2. 9.12 h5日记

    9.12 知识点补充: 属性继承例子,color.font(font-size/style/family/weight) 1.浏览器的默认字体大小是16px,谷歌浏览器的最小字体是10px,其他浏览器 ...

  3. oracle 直接复制表内容到新表

    不知道为什么,刚建的oracle数据库删除数据很慢,表里面有120多万数据,非常地慢 于是采用的复制的方法,命令如下: create table students_backup as select * ...

  4. angular2.0学习笔记2.创建hello world项目

    1.打开终端命令行窗口 2.切换到指定目录 E:\cd myobject 3.创建新项目 ng new angular2-helloworld 4.创建成功后,在angular2-helloworld ...

  5. Android.HowToDefineCustomView

    Custom View Errors E1 在使用自定义CustomView时,出现以下runtime error: Android.View.InflateException: Binary XML ...

  6. 在iOS中将string转成UTF-8编码

    在iOS开发中,特别是在对Web服务调用的时候,经常会遇到请求参数为中文的情况,那么这时候就需要将Url转成UTF-8编码才能进行请求.使用stringByAddingPercentEscapesUs ...

  7. Jackson高并发情况下,产生阻塞

    情况:在高并发情况下,查看线程栈信息,有大量的线程BLOCKED. 从线程栈得知,线程栈中出现了阻塞,锁在了com.fasterxml.jackson.databind.ser.SerializerC ...

  8. linux 软件编译问题汇总

    1.问题: fatal error: openssl/opensslv.h: No such file or directory 解决: sudo apt-get install libssl-dev ...

  9. 部署描述符(web.xml)和标注(annotation)

    部署描述符(web.xml) 详细信息可在http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html上下载web- ...

  10. 2017/2/10:Manven简介与项目管理(入门)

    1.Maven工程的创建 2.使用Manven manven配置文件主要集中在 http://m.blog.csdn.net/article/details?id=50316383