更新说明:
1、更正之前的unity的mapping xml格式以及读取方式
2、增加读取写在.config文件中的unity格式的section来进行注册的方式
3、增加了.config文件的section handler.
具体例子表现为:
setting.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?xml version="1.0" encoding="utf-8" ?> <unity>
<typeAliases>
<typeAlias alias="Interface" type="IOCFactoryUnitTest.Animal,IOCFactoryUnitTest"/>
<typeAlias alias="Object" type="IOCFactoryUnitTest.Dog,IOCFactoryUnitTest"/>
</typeAliases>
<containers>
<container name="containerOne">
<types>
<type type="Interface" mapTo="Object">
<lifetime type="singleton"/>
</type>
</types>
</container>
</containers> </unity> |
.config
<?xml version="1.0" encoding="utf-8" ?> <configuration> <configSections> <section name="unity" type="IOCFactory.Util.IOCFactoryUnitySectionHandler,IOCFactory"/> </configSections> <unity configSource="setting.xml" /> </configuration>
注册调用
1 |
factory.RegistFromSection( "unity" ); |