Using Spring.net in console application
- Download Spring.net in http://www.springframework.net/
- 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的更多相关文章
- Spring boot 全局配置文件application.properties
#更改Tomcat端口号 server.port=8090 #修改进入DispatcherServlet的规则为:*.htmlserver.servlet-path=*.html#这里要注意高版本的s ...
- 如何将Console application的Program函数变成支持async的?
如何将Console application的Program函数变成支持async的? class Program { static void Main(string[] args) { Task ...
- win32 console application 如何修改图标?
win32 console application ,不要看这名字高端大气上档次,让你摸不着头脑,其实他就是我们最先学习c语言那种黑色窗口的东西......话说他怎么修改图标呢?第一种方法是:右键-〉 ...
- Hello World 之 控制台版本(Console Application)
原文:Hello World 之 控制台版本(Console Application) 先来介绍下Hello, World "Hello, World"程序指的是只在计算机屏幕 ...
- RESTful Console Application
RESTful Console Application Introduction Inspirited by RESTFul architecture, A console application t ...
- spring boot 无法读取application.properties问题
spring boot 无法读取application.properties问题 https://bbs.csdn.net/topics/392374488 Spring Boot 之注解@Compo ...
- 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 ...
- C# 控制台程序(Console Application )启动后隐藏
背景 前段时间给项目编写了数据适配器,读取其他系统的数据后推送到MQ上,我们的系统通过订阅MQ的方式来获取.由于其他系统支持C#编程,且为了一时方便,选择了C#的控制台程序. 最近用户在使用中,总是不 ...
- .NET 如何隐藏Console Application的窗口
1)创建Console Application工程 2)修改Output type 为Windows Application即可
随机推荐
- svn-经常遇到问题解答办法积累(一)
1.对于一个SVN使用新手,第一步,肯定是如何获取代码到本地指定的目录. 步骤: (1)新建一个存放svn中某一个代码库的目录,加入该目录命名为:Proj1SVN (2)右键鼠标,选择SVN Chec ...
- jupyter notebook 初步使用配置调整
jupyter notebook 官方说明 初始部分: 如何打开特定的笔记本? 以下代码应在当前运行的笔记本服务器中打开给定的笔记本,必要时启动一个. jupyter notebook noteboo ...
- Android开发之利用ViewPager实现在Activity或Fragment中引入别的布局文件实现滑动并进行页面跳转
有些时候经常可以看到其他APP中有一排的图标,可以在一个界面中滑来滑去,并且图标可以进行点击事件进行页面的跳转.这里对这种方法的实现做出总结. 首先看一下图片: 下面这两种图片是在一个Fragment ...
- web框架--MVC、MTV
一.MVC框架: MVC 是一种使用 MVC(Model View Controller 模型-视图-控制器)设计创建 Web 应用程序的模式:[1] Model(模型)表示应用程序核心(比如数据库记 ...
- How to update XENTRY Connect C5 software with .iso file
07.2018 Xentry Mercedes SD Connect c5 software update manual for newbies: Important: If you have XDO ...
- 浅谈多重检验校正FDR
浅谈多重检验校正FDR Posted: 四月 12, 2017 Under: Basic By Kai no Comments 例如,在我们对鉴定到的差异蛋白做GO功能注释后,通常会计算一个p值 ...
- UVA 11324.The Largest Clique tarjan缩点+拓扑dp
题目链接:https://vjudge.net/problem/UVA-11324 题意:求一个有向图中结点数最大的结点集,使得该结点集中任意两个结点u和v满足:要目u可以到达v,要么v可以到达u(相 ...
- C#程序如何以管理员身份运行
VISTA 和 Windows 7 都使用了UAC来控制程序访问,对于一些需要使用管理员身份运行的程序就得右键以管理员身份运行. C# 编程中可以使程序自动使用管理员身份运行,也就是我们常常看到一些程 ...
- MySQL学习笔记-数据库内存
数据库内存 InnoDB存储引擎内存由以下几个部分组成:缓冲池(buffer pool).重做日志缓冲池(redo log buffer)以及额外的内存池(additional memory pool ...
- asio的网络通讯代码练手
asio的网络基本模板(单例模式 消息队列 ) // MyAsio.cpp: 定义控制台应用程序的入口点. // #include "stdafx.h" #include < ...