• 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. mysql 添加权限和撤销权限的实例(亲测可行)

    将当前数据库的表role_modules 的select权限赋予给用户uwangq: GRANT SELECT ON role_modules TO uwangq@'%' IDENTIFIED BY ...

  2. Jenkins+Jmeter+Ant自动化集成及邮件正文以html输出

    一.工具的安装与环境变量配置 1.依次安装Jenkins+Jmeter+Ant,具体安装步骤,此文不再详述 2.配置Jmeter&ant环境变量 Jmeter变量: 验证是否配置成功:cmd窗 ...

  3. c# 线程启动while(true) 死循环,里边的return导致线程退出情况,查错

    写了一个线程 线程下启动了一个循环 while(true) { 里边有个判断 如果为空不操作, 有余这个线程是后加的,老程序里边因为有个return没关注,导致线程退出而不能不听的监控 } 线程启动一 ...

  4. C# oracle 日期型字段,使用参数传值时,遇到ORA-01810: format code appears twice错误

    C#操作oracle数据库时,发现使用to_date('2014-01-03 18:00:00','yyyy-mm-dd hh:MM:ss')时,会出现ORA-01810: format code a ...

  5. Yii2 数据操作Query Builder查询数据

    Query Builder $rows = (new \yii\db\Query()) ->select(['dyn_id', 'dyn_name']) ->from('zs_dynast ...

  6. 利用gulp搭建less编译环境

       什么是less? 一种 动态 样式 语言. LESS 将 CSS 赋予了动态语言的特性,如 变量, 继承, 运算, 函数. LESS 既可以在 客户端 上运行 (支持IE 6+, Webkit, ...

  7. C#程序如何以管理员身份运行

    VISTA 和 Windows 7 都使用了UAC来控制程序访问,对于一些需要使用管理员身份运行的程序就得右键以管理员身份运行. C# 编程中可以使程序自动使用管理员身份运行,也就是我们常常看到一些程 ...

  8. JSP动作

    JSP动作元素在请求处理阶段起作用,他们会被转换成Java代码来执行操作,如访问一个Java对象或调用方法. JSP动作元素是用XML语法写成的. 动作元素基本上都是预定义的函数,JSP规范定义了一系 ...

  9. 我们最常见的UX设计交付成果有哪些?

    以下内容由摹客团队翻译整理,仅供学习交流,摹客iDoc是支持智能标注和切图的产品协作设计神器. 有人会好奇,用户体验(UX)设计师每天都在做些什么呢?说实话,有很多事情!作为UX专家,需要将自己的设计 ...

  10. Previous Permutation

    Similar to next permutation, the steps as follow: 1) Find k in the increasing suffix such that nums[ ...