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.