• 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. jq以固定开头的class属性的名称

    $("div[class^='pick']").css({'border-color':'#000000'}); div [class^="aaa"]

  2. JavaScript 中 如何判断一个元素是否在一个数组中

    <script type="text/javascript"> var arrList=['12','qw','q','v','d','t']; console.log ...

  3. Vue 快速原型开发

    快速原型开发 注意: 是:serve 而不是 server 通过使用 vue serve 和 vue build 命令对单个 *.vue 文件进行快速原型开发,不过这需要先额外安装一个全局的扩展 go ...

  4. (转)数组使用contains

    数组使用contains 今天发现一个怪问题,同样是.net3.5环境下的两个项目,一个里支持arr.contains("1"),一个就不支持,代码完全相同也不行.有时在不支持项目 ...

  5. Ubuntu几种常见乱码解决方法

    一.网页中的flash乱码:        ubuntu默认浏览器是Firefox,但是Ubuntu默认不安装像flash这种带版权的软件,所以当你浏览像youku或网页播放器时,这种带有 flash ...

  6. (xxx.55).toFixed(1) 无法正确进位处理

    参考:https://juejin.im/post/5a11a9fef265da43284073b4?utm_medium=fe&utm_source=weixinqun 根本原因在于2.55 ...

  7. java通过IP地址获取物理位置

    import java.io.*; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern ...

  8. RSS阅读

    添加自己的RSS源,订阅信息更高效.一目十行,快速获取信息的效果.

  9. (转贴)fusionCharts属性参考API

    一.FusionCharts的分类 关于FusionCharts的基本介绍我就不在这里浪费篇幅了,想了解的朋友自己去www.baigoogedu.com里面找吧.我就说说FusionCharts的官方 ...

  10. Linux下进行程序设计时,关于库的使用:

    一.gcc/g++命令中关于库的参数: -shared: 该选项指定生成动态连接库: -fPIC:表示编译为位置独立(地址无关)的代码,不用此选项的话,编译后的代码是位置相关的,所以动态载入时,是通过 ...