Spring. NET Learning Note 001: Environment collocation and Hello World

Source: Internet
Author: User

"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:

  1. <? XML version= "1.0" encoding="Utf-8" ?>
  2. <configuration>
  3. <configsections>
  4. <sectiongroup name="Spring">
  5. <section name="context" type="Spring.Context.Support.ContextHandler, Spring.core"/ >
  6. </sectiongroup>
  7. </configsections>
  8. <spring>
  9. <context>
  10. <resource uri="file://spring.xml.config"/>
  11. </Context>
  12. </Spring>
  13. </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:

  1. <? XML version= "1.0" encoding="Utf-8" ?>
  2. <objects xmlns="http://www.springframework.net">
  3. <object id="Hello" type="Springnetdemo.hello">
  4. <property name="Helloword" value= "hello! you can see this proves that you have succeeded! "/>
  5. </Object>
  6. </Objects>

5. Modify the original Program.cs file of the project:

  1. Using System;
  2. Using System.Collections.Generic;
  3. Using System.Text;
  4. Using Spring.context;
  5. Using Spring.Context.Support;
  6. Namespace Springnetdemo
  7. {
  8. public class Hello
  9. {
  10. private string Helloword;
  11. public string Helloword
  12. {
  13. get { return This.helloword;}
  14. set { This.helloword = value;}
  15. }
  16. }
  17. public class Program
  18. {
  19. static void Main (string[] args)
  20. {
  21. Iapplicationcontext context = Contextregistry.getcontext ();
  22. Hello hello = (hello) context.  GetObject ("Hello");
  23. Console.Write (hello. Helloword);
  24. Console.read ();
  25. }
  26. }
  27. }

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.