-keep-as3-metadata+=Inject
in addidtional compiler arguments.
I found a way to use it for easy injection. Here's a proof of concept. I think the source is worth more than words.
This part :
//Injection by id
[Inject(id="component1")]
public var a:Object ;
//injection by id simpler
[Inject("component2")]
public var b:Object;
//injection by type
[Inject(type="poc.SimpleComponent2")]
public var c:SimpleComponent2;
//Injection by type guess
[Inject]
public var d:ExplicitCommandImpl;
//Injection by type works with interfaces, basic classess too
[Inject]
public var e:IExplicitCommand;
private var _f:Object;
//Works with getters and setters too
//Inject with given context
[Inject(type="poc.SimpleComponent2", context="someContextName")]
public function get f():Object
{
return _f;
}
public function set f(val:Object):void
{
_f = val;
}
does the trick.
The final trace is :
a [object ExplicitCommandImpl]
b [object SimpleComponent]
c [object SimpleComponent2]
d [object ExplicitCommandImpl]
e [object ExplicitCommandImpl]
f [object SimpleComponent2]
I think It's an easy way to join application components. The injected components are get by methods mentioned in part2 :
getComponentById and getComponentByInterface so it's just a shortcut.Just the -keep-as3-metadata part is tricky during release build. There's a bug on Adobe bugtracker.
2 comments:
I will be using your Container as an example of projects that use metadata in my 360 Flex presentation next week. I hope you don’t mind. :)
I am presenting on how to use metadata to create better APIs and will cite you as someone who has done this.
By the way, with Flex Builder 3, if your SWC was compiled with the -keep-as3-metadata option, any project the SWC is used in don’t need to add it.
Thanks for info. Could You please send me some link to the presentation ?
Prześlij komentarz