Spring.net配置

创建内部类对象

<object id="exampleObject" type="Examples.ExampleObject+Person, ExamplesLibrary"/>

 

通过工厂类的静态方法创建对象

<object id="exampleObject"
      type="Examples.ExampleObjectFactory, ExamplesLibrary"
      factory-method="CreateInstance"/>

 

通过工厂类对象的方法创建对象

<object id="exampleFactory" type="...">object>

<object id="exampleObject"
      factory-method="CreateInstance"
      factory-object="exampleFactory"/>

 

 

普通注射

<object id="myConnection" type="System.Data.SqlClient.SqlConnection">
      "ConnectionString"
          value="Integrated Security=SSPI;database=northwind;server=mySQLServer"/>
object>
 

构造方法注射

<object name="exampleObject" type="SimpleApp.ExampleObject, SimpleApp">
  "years" value="7500000"/>
  "ultimateAnswer" value="42"/>
object>

 

属性引用其他对象

<object id="theTargetObject" type="...">object>

<object id="theClientObject" type="...">
  "targetName"> 
    object="theTargetObject"/> 
  
object>

或者

<object id="theTargetObject" type="..."> 
  . . .
object>

<object id="theClientObject" type="...">
  "targetName" value="theTargetObject"/> 
object>

 

 

Inline对象

<object id="outer" type="...">
  "target"> 
    <object type="ExampleApp.Person, ExampleApp"> 
      "name" value="Tony"/> 
      "age" value="51"/> 
    object>
  
object>

 

 

注射容器

<object id="moreComplexObject" type="Example.ComplexObject">
      
      "SomeList">
          <list>
              <value>a list element followed by a referencevalue>
              <ref object="myConnection"/>
          
      
      
      "SomeDictionary">
          <dictionary>
              "a string => string entry" value="just some string"/>
              ref="myKeyObject" value-ref="myConnection"/>
          
      
      
      "SomeNameValue">
          <name-values>
              "HarryPotter" value="The magic property"/>
              "JerrySeinfeld" value="The funny (to Americans) property"/>
          
      
      
      "someSet">
          <set>
              <value>just some stringvalue>
              <ref object="myConnection"/>
          
      
  object>
 

 

引用对象的属性

<object name="person" type="Spring.Objects.TestObject, Spring.Core.Tests">
  "age" value="20"/>
  "spouse">
    <object type="Spring.Objects.TestObject, Spring.Core.Tests">                      
      "age" value="21"/>
    object>
            
object>
        
// will result in 21, which is the value of property 'spouse.age' of object 'person'        
<object name="theAge" type="Spring.Objects.Factory.Config.PropertyRetrievingFactoryObject, Spring.Core">
  "TargetObject" ref="person"/>
  "TargetProperty" value="spouse.age"/>
object>
 

static属性

<object id="currentUICulture" 
        type="Spring.Objects.Factory.Config.PropertyRetrievingFactoryObject, Spring.Core">
  "StaticProperty">
      <value>System.Globalization.CultureInfo.CurrentUICulture, Mscorlibvalue>
  
object>

 

0
0
(请您对文章做出评价)

你可能感兴趣的:(Spring.net配置)