<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>bonashen &#187; ioc</title>
	<atom:link href="http://www.bonashen.com/archives/tag/ioc/feed" rel="self" type="application/rss+xml" />
	<link>http://www.bonashen.com</link>
	<description>关注造船行业信息化</description>
	<lastBuildDate>Thu, 20 Oct 2011 14:05:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Robotlegs IOC 接口实例化</title>
		<link>http://www.bonashen.com/archives/312</link>
		<comments>http://www.bonashen.com/archives/312#comments</comments>
		<pubDate>Thu, 21 Jan 2010 20:59:10 +0000</pubDate>
		<dc:creator>bona</dc:creator>
				<category><![CDATA[FLEX专题]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[ioc]]></category>
		<category><![CDATA[robotlegs]]></category>

		<guid isPermaLink="false">http://192.168.30.35/wordpress/?p=312</guid>
		<description><![CDATA[目前在开发程序时要实例化某一接口，而不知道接口是哪一个类实现，如果用Robotlegs来做是很好的。 我尝试用 injector.instantiate(IRobot); 但是程序始终报错，后来才发现接口是不能直接用instantiate方法来做。如果要用Injector来做，可以采用如下方法： injector.getMapping(IRobot).getResponse() as IRobot; 平时一般向类中注入接口代码如下： AS CODE： public&#160;class&#160;Robot&#160;implements&#160;IRobot&#160;{&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;private&#160;var&#160;_leftLeg&#160;:&#160;ILeg;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;private&#160;var&#160;_rightLeg&#160;:&#160;ILeg;&#160;&#160; &#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;public&#160;function&#160;get&#160;leftLeg()&#160;:&#160;ILeg&#160;{&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return&#160;_leftLeg;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;[Inject(name=&#34;leftLeg&#34;)]&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;public&#160;function&#160;set&#160;leftLeg(leg&#160;:&#160;ILeg)&#160;:&#160;void&#160;{&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;_leftLeg&#160;=&#160;leg;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;public&#160;function&#160;get&#160;rightLeg()&#160;:&#160;ILeg&#160;{&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return&#160;_rightLeg;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;[Inject(name=&#34;rightLeg&#34;)]&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;public&#160;function&#160;set&#160;rightLeg(leg&#160;:&#160;ILeg)&#160;:&#160;void&#160;{&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;_rightLeg&#160;=&#160;leg;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;}&#160;&#160; &#160;&#160;&#160;&#160;}&#160;&#160; 上面代码中ILeg就是在Robot类实例化时注入，将会由Injector类自动调用injector.getMapping(ILeg).getResponse() as ILeg; 另外还有一个收获，如下代码，先映射Robot,IRobot为单例： AS CODE: private&#160;function&#160;init(e:Event):void{&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;injector&#160;=&#160;new&#160;Injector();&#160;&#160; &#8230; <a href="http://www.bonashen.com/archives/312">继续阅读 <span class="meta-nav">&#8594;</span></a>]]></description>
		<wfw:commentRss>http://www.bonashen.com/archives/312/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

