Spring. Net learning notes (5)-set injection, spring.net learning notes

Source: Internet
Author: User

Spring. Net learning notes (5)-set injection, spring.net learning notes
I. Development Environment

System: Win10

Compiler: VS2013

. Net version:. net framework4.5

Ii. Assembly

Spring. Core. dll 1.3.1

Common. Loggin. dll

Iii. Development Process 1. Project Structure

Namespace SpringNetSetDi {public class Person {public string RealName {get; set;} public string NickName {get; set;} public string LoginName {get; set;} public string ShowName {get; set ;}}}3. Compile Animal. cs

namespace SpringNetSetDi{    public class Animal    {        public string Name { get; set; }        public IList TypeList { get; set; }    }}
4. Compile Zoo. cs
namespace SpringNetSetDi{    public class Zoo    {        public List<Animal> AnimalList { get; set; }    }}
6. The configuration file App. config
<? Xml version = "1.0" encoding = "UTF-8"?> <Configuration> <configSections> <sectionGroup name = "spring"> <section name = "context" type = "Spring. context. support. contextHandler, Spring. core "/> <section name =" objects "type =" Spring. context. support. defaultSectionHandler, Spring. core "/> </sectionGroup> </configSections> <spring> <context> <resource uri =" config: // spring/objects "> </resource> </context> <objects xmlns =" http://www.springframework.net "> <! -- 01 set null --> <object name = "person" type = "SpringNetSetDi. person, springNetSetDi "> <property name =" ShowName "value =" Kimisme "> </property> <property name =" RealName "value =" "> </property> <property name = "NickName"> <value> </property> <property name = "LoginName"> <null/> </property> </object> <! -- 02IList type Injection --> <object name = "animal" type = "SpringNetSetDi. animal, springNetSetDi "> <property name =" TypeList "> <list element-type =" string "> <value> mammals </value> <value> birds </value> <value> crawling class </value> <value> insect class </value> <value> amphibious class </value> </list> </property> </object> <! -- 03 generic List injection --> <object name = "zoo" type = "SpringNetSetDi. zoo, SpringNetSetDi "> <property name =" AnimalList "> <list element-type =" SpringNetSetDI. animal, SpringNetSetDi "> <object type =" SpringNetSetDi. animal, springNetSetDi "> <property name =" Name "value =" Eagle "> </property> <property name =" TypeList "> <list element-type =" string "> <value> birds </value> </list> </property> </object> </objects> </spring> <startup> <supportedRuntime version = "v4.0" sku = ". NETFramework, Version = v4.5 "/> </startup> </configuration>
7. Console code
namespace SpringNetSetDi{    class Program    {        static void Main(string[] args)        {            IApplicationContext context = ContextRegistry.GetContext();            Person person = context.GetObject("person") as Person;            Animal animal = context.GetObject("animal") as Animal;            Zoo zoo = context.GetObject("zoo") as Zoo;            Console.ReadKey();        }    }}
Iv. Description

It took me a long time to solve the problem.

Related Article

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.