"Copyright notice: This article for the Special Dimension blog original, without permission declined reproduced. If you want to reprint, please be sure to mention this blog address when reproduced . "
1. Preface
I've been in touch with spring. NET for a long time, but have never been used in a project, and now try to use it in new projects.
2. Steps
1. New Console Project
2. Installation dependent
In PM condole input:install-package spring.core–pre
Spring.core and common.logging are installed automatically
3, New app. Config, the code 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="file://spring.xml.config"/>
- </Context>
- </Spring>
- </configuration>
4, the new Spring.xml.config (this name can be customized, if you want to rename, then in the App. Config Rescource also need to be modified), the code is as follows:
- <? XML version= "1.0" encoding="Utf-8" ?>
- <objects xmlns="http://www.springframework.net">
- <object id="Hello" type="Springnetdemo.hello">
- <property name="Helloword" value= "hello! you can see this proves that you have succeeded! "/>
- </Object>
- </Objects>
5. Modify the original Program.cs file of the project:
- Using System;
- Using System.Collections.Generic;
- Using System.Text;
- Using Spring.context;
- Using Spring.Context.Support;
- Namespace Springnetdemo
- {
- public class Hello
- {
- private string Helloword;
- public string Helloword
- {
- get { return This.helloword;}
- set { This.helloword = value;}
- }
- }
- public class Program
- {
- static void Main (string[] args)
- {
- Iapplicationcontext context = Contextregistry.getcontext ();
- Hello hello = (hello) context. GetObject ("Hello");
- Console.Write (hello. Helloword);
- Console.read ();
- }
- }
- }
Description: Here's hello. Helloword is spring.net is injected through XML configuration implementations. If you have questions, you can leave a message.
3. Note
There may be an error here suggesting that the common.logging version is too low and the workaround is to reinstall Common.logging:
Install-package common.logging
4.Web Project Considerations
You need to enter:
5.install-package Spring.web.mvc4–pre
If you have any questions, can give me a message , I will take time to answer.
I Weibo: @LeaveBugsAway welcome nagging.
Spring. NET Learning Note 001: Environment collocation and Hello World