|
Project Information
Members
Featured
Downloads
Wiki pages
Links
|
SmartyPants IOCWelcomeWelcome to the main repository for SmartyPants IOC, which is a dependency injection framework designed for use with Adobe Flex. Why SmartyPants?There are a few IOC frameworks around at the moment: Prana (now Spring Actionscript) was probably the first serious DI framework for Flex to get much notice. There's also Swiz, and others. What sets Smartypants apart from these frameworks?
Getting startedDownload the .swc file from here, or checkout the code via SVN. The project is young, and the docs are growing, but grow they will! Check out the wiki here, or join the discussion group if you'd like to know more. The !ASDocs are currently offline but will return very shortly! A simple example<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" preinitialize="setupInjector()" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.controls.Alert;
import net.expantra.smartypants.SmartyPants;
import net.expantra.smartypants.Injector;
private var injector : Injector;
[Inject(name="wsdl")]
[Bindable]
public var wsdlLocation : String;
[Inject(live, name="liveExample")]
[Bindable]
public var textBox2Value : String = "Not injected";
private function setupInjector() : void
{
injector = SmartyPants.getOrCreateInjectorFor(this);
}
private function setUpRules() : void
{
injector.newRule().whenAskedFor(String).named("wsdl").useInstance("http://www.server.com/service/main.wsdl");
injector.newRule().whenAskedFor(String).named("liveExample").useBindableProperty(this, ["tb1", "text"]);
}
private function inject() : void
{
try
{
setUpRules();
injector.injectInto(this);
}
catch (e : Error)
{
trace(e.getStackTrace());
Alert.show("Oops! " + e, "Error performing injection");
}
}
]]>
</mx:Script>
<mx:Panel title="Smartypants IOC demo" horizontalCenter="0" verticalCenter="0">
<mx:Form>
<mx:FormItem label="WSDL location">
<mx:TextInput text="{ wsdlLocation }" editable="false"/>
</mx:FormItem>
<mx:FormItem label="Source Textbox">
<mx:TextInput id="tb1"/>
</mx:FormItem>
<mx:FormItem label="Destination Textbox">
<mx:TextInput id="tb2" text="{ textBox2Value }"/>
</mx:FormItem>
<mx:HBox width="100%" horizontalAlign="right">
<mx:Button label="Inject into this" click="inject()"/>
</mx:HBox>
</mx:Form>
</mx:Panel>
</mx:Application>
|