您的位置:首页 > 编程语言 > Java开发

Spring.NET 配置

2010-09-30 10:28 197 查看
创建内部类对象

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


.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}

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

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

.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}

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

<objectid="exampleFactory"type="..."></object>

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

.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}

普通注射

<objectid="myConnection"type="System.Data.SqlClient.SqlConnection">
<property
name="ConnectionString"
value="IntegratedSecurity=SSPI;database=northwind;server=mySQLServer"/>
</object>

构造方法注射

<objectname="exampleObject"type="SimpleApp.ExampleObject,SimpleApp">
<constructor-argname="years"value="7500000"/>
<constructor-argname="ultimateAnswer"value="42"/>
</object>


属性引用其他对象

<objectid="theTargetObject"type="..."></object>

<objectid="theClientObject"type="...">
<propertyname="targetName">
<idrefobject="theTargetObject"/>
</property>
</object>


.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}

或者

<objectid="theTargetObject"type="...">
...
</object>

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

.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}

Inline对象

<objectid="outer"type="...">
<propertyname="target">
<objecttype="ExampleApp.Person,ExampleApp">
<propertyname="name"value="Tony"/>
<propertyname="age"value="51"/>
</object>
</property>
</object>

.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}


注射容器

<objectid="moreComplexObject"type="Example.ComplexObject">
<!--
resultsinacalltothesetteroftheSomeList(System.Collections.IList)property
-->
<propertyname="SomeList">
<list>
<value>alistelementfollowedbyareference</value>
<refobject="myConnection"/>
</list>
</property>
<!--
resultsinacalltothesetteroftheSomeDictionary(System.Collections.IDictionary)property
-->
<propertyname="SomeDictionary">
<dictionary>
<entrykey="astring=>stringentry"value="justsomestring"/>
<entrykey-ref="myKeyObject"value-ref="myConnection"/>
</dictionary>
</property>
<!--
resultsinacalltothesetteroftheSomeNameValue(System.Collections.NameValueCollection)property
-->
<propertyname="SomeNameValue">
<name-values>
<addkey="HarryPotter"value="Themagicproperty"/>
<addkey="JerrySeinfeld"value="Thefunny(toAmericans)property"/>
</name-values>
</property>
<!--
resultsinacalltothesetteroftheSomeSet(Spring.Collections.ISet)property
-->
<propertyname="someSet">
<set>
<value>justsomestring</value>
<refobject="myConnection"/>
</set>
</property>
</object>

.csharpcode,.csharpcodepre
{
font-size:small;
color:black;
font-family:consolas,"CourierNew",courier,monospace;
background-color:#ffffff;
/*white-space:pre;*/
}
.csharpcodepre{margin:0em;}
.csharpcode.rem{color:#008000;}
.csharpcode.kwrd{color:#0000ff;}
.csharpcode.str{color:#006080;}
.csharpcode.op{color:#0000c0;}
.csharpcode.preproc{color:#cc6633;}
.csharpcode.asp{background-color:#ffff00;}
.csharpcode.html{color:#800000;}
.csharpcode.attr{color:#ff0000;}
.csharpcode.alt
{
background-color:#f4f4f4;
width:100%;
margin:0em;
}
.csharpcode.lnum{color:#606060;}

引用对象的属性

<objectname="person"type="Spring.Objects.TestObject,Spring.Core.Tests">
<propertyname="age"value="20"/>
<propertyname="spouse">
<objecttype="Spring.Objects.TestObject,Spring.Core.Tests">
<propertyname="age"value="21"/>
</object>
</property>
</object>

//willresultin21,whichisthevalueofproperty'spouse.age'ofobject'person'
<objectname="theAge"type="Spring.Objects.Factory.Config.PropertyRetrievingFactoryObject,Spring.Core">
<propertyname="TargetObject"ref="person"/>
<propertyname="TargetProperty"value="spouse.age"/>
</object>

static属性

<objectid="currentUICulture"
type="Spring.Objects.Factory.Config.PropertyRetrievingFactoryObject,Spring.Core">
<propertyname="StaticProperty">
<value>System.Globalization.CultureInfo.CurrentUICulture,Mscorlib</value>
</property>
</object>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: