Problems with the exaple

9 views
Skip to first unread message

Tom K

unread,
Nov 2, 2009, 12:09:54 PM11/2/09
to Smartypants IOC
Hi,

I am having some problems with SmartPants.
Basically I get that I have 0 injection points.

Here is my mxml app:

<?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
{
trace("setup Injector");
injector = SmartyPants.getOrCreateInjectorFor(this);

}

private function setUpRules() : void
{
injector.newRule().whenAskedFor(String).named
("wsdl").useValue("http://www.server.com/service/main.wsdl");
injector.newRule().whenAskedFor(String).named
("liveExample").useBindableProperty(this, ["tb1", "text"]);
}

private function inject() : void
{
try
{
trace("injecting");
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>


Console spits out
setup Injector on startup
and when I click the button:

injecting
[Debug / net.expantra.smartypants.impl.InjectorImpl ] The object
(Instance provider for a String (http://www.server.com/service/
main.wsdl)) has 0 injection points.
[Debug / net.expantra.smartypants.impl.InjectorImpl ] Injectee
Instance provider for a String (http://www.server.com/service/
main.wsdl) has 0 [PostConstruct] function(s)
[Debug / net.expantra.smartypants.impl.live.LiveInjectionManager ]
Registering updating source for class String, named "liveExample",
host is "SmartyPantsDemo0"
[Debug / net.expantra.smartypants.impl.InjectorImpl ] The object
(LiveProvider for magic key "String.liveExample") has 0 injection
points.
[Debug / net.expantra.smartypants.impl.InjectorImpl ] Injectee
LiveProvider for magic key "String.liveExample" has 0 [PostConstruct]
function(s)
[Debug / net.expantra.smartypants.impl.live.LiveInjectionManager ]
Updating listeners for String.liveExample
[Debug / net.expantra.smartypants.impl.InjectorImpl ] The object
(SmartyPantsDemo0) has 0 injection points.
[Debug / net.expantra.smartypants.impl.InjectorImpl ] Injectee
SmartyPantsDemo0 has 0 [PostConstruct] function(s)



I am using classes not the swc, I've got FlexBuilder installed with
Flex 3.4 SDK.
Any ideas what am I doing wrong?

Cheers,

Tom

Josh McDonald

unread,
Nov 2, 2009, 6:12:11 PM11/2/09
to Smartypants IOC
If you're using the source and not the .swc, you'll need to add these
to your compiler options:

-keep-as3-metadata
+=Inject,InjectInto,InjectIntoContents,Singleton,PostConstruct

-Josh

Tom K

unread,
Nov 3, 2009, 5:15:32 AM11/3/09
to Smartypants IOC
Cheers Josh, works like a charm :)

Tom
Reply all
Reply to author
Forward
0 new messages