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即可
随机推荐
- 求助Ubuntu16.10如何设置默认启动为字符界面
字符界面:sudo systemctl set-default multi-user.target图形界面:sudo systemctl set-default graphical.target
- 制作根文件系统之内核如何启动init进程
start_kernel其实也是内核的一个进程,它占用了进程号0,start_kernel的内容简写如下: asmlinkage void __init start_kernel(void) //内核 ...
- ftp中ftpClient类的API
org.apache.commons.NET.ftp Class FTPClient类FTPClient java.lang.Object java.lang.Object继承 org.apache ...
- Eclipse中logcat过滤器的使用
logcat里信息繁多,用过滤器可以方便快捷的找到我们要查找的信息. 我们可以在打开Eclipse之后,选择Window –> Show View ->Other菜单,然后在Android ...
- Java 7.21 游戏:豆机(C++&Java)
PS: 难点在于,随机之后的分隔,理解就很容易了 注意:槽的奇偶情况 C++: #include<iostream> #include<ctime> #include<s ...
- Hadoop(二) HADOOP集群搭建
一.HADOOP集群搭建 1.集群简介 HADOOP集群具体来说包含两个集群:HDFS集群和YARN集群,两者逻辑上分离,但物理上常在一起 HDFS集群: 负责海量数据的存储,集群中的角色主要有 Na ...
- ActiveMq unsupported major.minor version 52.0
网上是说ActiveMq已经编译好的版本和运行的java版本不一致导致的,看了一下MF文件 用的Jdk版本是1.8,而我们当前系统的java版本是1.7,所以尝试重新下载之前的ActiveMq的版本. ...
- Rsync同步设置的一例
以下文档于2014-12-10更新 先在服务端操作 #wget http://pkgs.repoforge.org/rsync/rsync-3.0.9-2.el6.rfx.x86_64.rpm # ...
- 无法创建.gitignore文件,提示必须输入文件名称
If you're using Windows it will not let you create a file without a filename in Windows Explorer. It ...
- Best Sightseeing Pair LT1014
Given an array A of positive integers, A[i] represents the value of the i-th sightseeing spot, and t ...