Constructor injection

11 views
Skip to first unread message

Josh McDonald

unread,
Aug 5, 2009, 1:13:59 AM8/5/09
to smartyp...@googlegroups.com
Hey guys, here's the plan for constructor injection:

  1. All params to be injected initially, assistedInject will be added once it's settled down and appears to be working.
  2. Only Name/type annotaions required, like this:

    [Inject(parameter=1,named="fooWSDL")]
    [Inject(parameter=3,type="mx.rpc.soap.WebService")]
    function MyObject(wsdl:String, someDependency:DependencyInterface, serviceProvider:Provider) {...}
  3. Coming soon (along with AS3Commons-reflect).
Thoughts? Complaints? See anything you can't do with this? Think "parameter" is a dumb name for the annotation? Think I should count at 0 instead of 1 for params? Let me know before it escapes ;-)

-Josh

--
"Therefore, send not to know For whom the bell tolls. It tolls for thee."

Josh 'G-Funk' McDonald
  -  jo...@joshmcdonald.info
  -  http://twitter.com/sophistifunk
  -  http://flex.joshmcdonald.info/

Shaun Smith

unread,
Aug 6, 2009, 6:53:00 AM8/6/09
to Smartypants IOC
Awesome! Looks flexible, usable.

Starting with 0 makes sense if you push it. Actually.. it makes me
think of "arg0, arg1, arg2"..

On the other hand.. when you say it aloud: parameter 1 is "the first
parameter".

How is this done with other frameworks (Guice etc)?


On Aug 5, 7:13 am, Josh McDonald <j...@joshmcdonald.info> wrote:
> Hey guys, here's the plan for constructor injection:
>
>    1. All params to be injected initially, assistedInject will be added once
>    it's settled down and appears to be working.
>    2. Only Name/type annotaions required, like this:
>
>    [Inject(parameter=1,named="fooWSDL")]
>    [Inject(parameter=3,type="mx.rpc.soap.WebService")]
>    function MyObject(wsdl:String, someDependency:DependencyInterface,
>    serviceProvider:Provider) {...}
>    3. Coming soon (along with AS3Commons-reflect).
>
> Thoughts? Complaints? See anything you can't do with this? Think "parameter"
> is a dumb name for the annotation? Think I should count at 0 instead of 1
> for params? Let me know before it escapes ;-)
>
> -Josh
>
> --
> "Therefore, send not to know For whom the bell tolls. It tolls for thee."
>
> Josh 'G-Funk' McDonald
>   -  j...@joshmcdonald.info

Josh McDonald

unread,
Aug 6, 2009, 7:19:14 AM8/6/09
to smartyp...@googlegroups.com
They're all in Java, so they're allowed to annotate parameters, but we're not :)

Argument 0 is usually "this" in most systems, which is why I though I'd start the explicit args at #1, but if it's likely to be confusing I'm definitely not married to the idea!

-Josh

2009/8/6 Shaun Smith <dar...@gmail.com>
  -  jo...@joshmcdonald.info

Richard

unread,
Aug 7, 2009, 3:15:26 AM8/7/09
to Smartypants IOC
Hi Josh

Great news. Looking forward to the implementation.

As for whether the first parameter should be parameter 0 or 1, so long
as it's documented I don't think it really matters. Although since all
collections in actionscript index from 0 it might be more
understandable (and maybe also avoid a +1 in your code) if you count
the parameters from 0 too.

Richard

Till Schneidereit

unread,
Sep 30, 2009, 10:52:58 AM9/30/09
to Smartypants IOC
Hey Josh,

as I'm working on adding ctor injection to SwiftSuspenders as well,
maybe we could coordinate the syntax, so that people can keep swapping
injectors without having to change the metadata?

Did you actually manage to make your proposed syntax work? As far as I
can tell, mxmlc doesn't keep metadata for constructors. That's why
Parsley implements ctor injection by adding metadata to the class
itself[1] - which seems fine to me as AS3 doesn't support multiple
ctors anyway.
Also, circumventable bugs[2] aside, I don't see a reason for
specifying the parameter's type - it seems as if the xml returned by
describeType contains that. Given that, maybe adding metadata should
be entirely optional and only needed for named injections.

If that works out, maybe we could come up with a reduced syntax,
something like
[Inject(name='namedInjection1', name='namedInjection2')]
which would translate to the following metadata:
<metadata name="Inject">
<arg key="name" value="namedInjection1"/>
<arg key="name" value="namedInjection2"/>
</metadata>


cheers,
till


[1] http://www.spicefactory.org/parsley/docs/2.0/manual/injection.php
[2] see above

On Aug 5, 7:13 am, Josh McDonald <j...@joshmcdonald.info> wrote:
> Hey guys, here's the plan for constructor injection:
>
>    1. All params to be injected initially, assistedInject will be added once
>    it's settled down and appears to be working.
>    2. Only Name/type annotaions required, like this:
>
>    [Inject(parameter=1,named="fooWSDL")]
>    [Inject(parameter=3,type="mx.rpc.soap.WebService")]
>    function MyObject(wsdl:String, someDependency:DependencyInterface,
>    serviceProvider:Provider) {...}
>    3. Coming soon (along with AS3Commons-reflect).
>
> Thoughts? Complaints? See anything you can't do with this? Think "parameter"
> is a dumb name for the annotation? Think I should count at 0 instead of 1
> for params? Let me know before it escapes ;-)
>
> -Josh
>
> --
> "Therefore, send not to know For whom the bell tolls. It tolls for thee."
>
> Josh 'G-Funk' McDonald
>   -  j...@joshmcdonald.info

Josh McDonald

unread,
Sep 30, 2009, 5:56:58 PM9/30/09
to smartyp...@googlegroups.com
Hi Till,

I haven't gotten too far into it yet, at the moment it's just some failing tests. That issue about metadata on constructors worries me though, I hadn't come across it. I'd definitely like to keep the metadata consistent if possible though, that's a great idea. Thursday's my "churn pending business admin BS" night, but I'll try and make a start on the impl tonight, and post back my progress / ideas.

Cheers,

-Josh

2009/10/1 Till Schneidereit <tschne...@gmail.com>
  -  jo...@joshmcdonald.info

Till Schneidereit

unread,
Oct 1, 2009, 10:31:58 AM10/1/09
to smartyp...@googlegroups.com
Hey Josh,

I'll also try to implement ctor injection in SwiftSuspenders until
tomorrow, maybe we can then compare results and try to unify metadata.
I'll keep you posted on how it goes.


cheers,
till
--
Till Schneidereit
Schneidereit Link GbR
technical concept, consulting, development
Tel: +49 40 970 7848 1

Till Schneidereit

unread,
Oct 2, 2009, 8:44:16 PM10/2/09
to smartyp...@googlegroups.com
Hey Josh,

I've completed my implementation of ctor (and method) injection. After
jumping through some hoops, everything seems to work fine.
I settled on only requiring metadata for named injections as the
parameters and their types themselves can be gathered through
describeType.
Maybe you could take a look at
http://github.com/tschneidereit/SwiftSuspenders
and tell me if that solution (mostly the metadata, of course) is ok
with you - or propose changes.
If you've got a moment for that anytime soon, obviously.


cheers,
till

Josh McDonald

unread,
Oct 3, 2009, 10:31:54 PM10/3/09
to smartyp...@googlegroups.com
Looks good, but I'm worried about relying on the ordering of metadata, as it might get broken or changed by future versions of the compiler, or third-party swf-mangling tools. On the other hand, I know that I'm usually being more cautious than I need to when I worry about shit like that :)

2009/10/3 Till Schneidereit <tschne...@gmail.com>

Till Schneidereit

unread,
Oct 5, 2009, 9:56:08 AM10/5/09
to smartyp...@googlegroups.com
Mmh. I honestly can't imagine that Adobe would break that. Mostly
because it would break symmetry with how the rest of the language is
parsed and because there are quite a lot of solutions out there that
depend on metadata nowadays. I admittedly can't name any that depend
on the order of metadata - but then again: Why should the have allowed
multiple metadata arguments in the first place, if they would later go
and completely break using them?

Josh McDonald

unread,
Oct 5, 2009, 8:29:33 PM10/5/09
to smartyp...@googlegroups.com
I agree, the chances of them breaking it are pretty small. I'd *really* like to get my hands on this iPhone target for Flash, I wonder what that does to metadata (and the rest of describeType). I'm gonna bug Ted to test it :)

I was playing around over the weekend, and your way definitely looks like the only way to get constructor injection in. It just *really* bugs me that we're stuck with our annotations being so far away from the code they're annotating :'( This whole "using Flash to build grown-up apps" thing seems to have sneaked up on Adobe...

Wondering if you know where/why SwiftSuspenders is faster than SP? I'm assuming it's mainly my dodgey reflection code, which will be replaced with commons-reflection sometime soon, but I've done zero benchmarking, mainly because it's been fast enough for my needs so far.

-Josh

2009/10/5 Till Schneidereit <tschne...@gmail.com>

Till Schneidereit

unread,
Oct 6, 2009, 6:13:26 AM10/6/09
to smartyp...@googlegroups.com
Hey Josh,

On Tue, Oct 6, 2009 at 02:29, Josh McDonald <jo...@joshmcdonald.info> wrote:
> I agree, the chances of them breaking it are pretty small. I'd *really* like
> to get my hands on this iPhone target for Flash, I wonder what that does to
> metadata (and the rest of describeType). I'm gonna bug Ted to test it :)

Interesting though. They're most certainly using LLVM to compile to
native applications, so there might be differences in how some parts
of the language are translated. Do tell me the results of you get Ted
to let you test it!

>
> I was playing around over the weekend, and your way definitely looks like
> the only way to get constructor injection in. It just *really* bugs me that
> we're stuck with our annotations being so far away from the code they're
> annotating :'( This whole "using Flash to build grown-up apps" thing seems
> to have sneaked up on Adobe...

That's really annoying, yes! And I think it doesn't even make sense at
all. Maybe someone should hack the compiler to keep metadata for
constructors, shouldn't be too hard, I guess.
At least we don't need any metadata at all if we don't want to define
named injections. A big "if", certainly, but at least it's something
;)

>
> Wondering if you know where/why SwiftSuspenders is faster than SP? I'm
> assuming it's mainly my dodgey reflection code, which will be replaced with
> commons-reflection sometime soon, but I've done zero benchmarking, mainly
> because it's been fast enough for my needs so far.

To be honest, I've got no idea. I started drilling into SP but then I
had this idea in my head about how to build a really reduced DI
solution, so I tried that out instead.
I guess it's either something in the reflection code as you say, or
the fact that the Flash Player doesn't really deal that well with
deeply nested stacks, such as the ones you probably get through SPs
API. If I had to bet, I'd put money on the reflection code, though. Or
maybe it's simply some hidden bug?


cheers,
till

Richard Lord

unread,
Oct 7, 2009, 2:53:24 AM10/7/09
to Smartypants IOC
I asked specifically whether describeType works with the iPhone
target, and was told if it doesn't "then its a bug we'd like to know
about". I didn't check into the details.

Richard

On Oct 6, 1:29 am, Josh McDonald <j...@joshmcdonald.info> wrote:
> I agree, the chances of them breaking it are pretty small. I'd *really* like
> to get my hands on this iPhone target for Flash, I wonder what that does to
> metadata (and the rest of describeType). I'm gonna bug Ted to test it :)
>
> I was playing around over the weekend, and your way definitely looks like
> the only way to get constructor injection in. It just *really* bugs me that
> we're stuck with our annotations being so far away from the code they're
> annotating :'( This whole "using Flash to build grown-up apps" thing seems
> to have sneaked up on Adobe...
>
> Wondering if you know where/why SwiftSuspenders is faster than SP? I'm
> assuming it's mainly my dodgey reflection code, which will be replaced with
> commons-reflection sometime soon, but I've done zero benchmarking, mainly
> because it's been fast enough for my needs so far.
>
> -Josh
>
> 2009/10/5 Till Schneidereit <tschneider...@gmail.com>
>
>
>
>
>
> > Mmh. I honestly can't imagine that Adobe would break that. Mostly
> > because it would break symmetry with how the rest of the language is
> > parsed and because there are quite a lot of solutions out there that
> > depend on metadata nowadays. I admittedly can't name any that depend
> > on the order of metadata - but then again: Why should the have allowed
> > multiple metadata arguments in the first place, if they would later go
> > and completely break using them?
>
> > On Sun, Oct 4, 2009 at 04:31, Josh McDonald <j...@joshmcdonald.info>
> > wrote:
> > > Looks good, but I'm worried about relying on the ordering of metadata, as
> > it
> > > might get broken or changed by future versions of the compiler, or
> > > third-party swf-mangling tools. On the other hand, I know that I'm
> > usually
> > > being more cautious than I need to when I worry about shit like that :)
>
> > > 2009/10/3 Till Schneidereit <tschneider...@gmail.com>
>
> > >> Hey Josh,
>
> > >> I've completed my implementation of ctor (and method) injection. After
> > >> jumping through some hoops, everything seems to work fine.
> > >> I settled on only requiring metadata for named injections as the
> > >> parameters and their types themselves can be gathered through
> > >> describeType.
> > >> Maybe you could take a look at
> > >>http://github.com/tschneidereit/SwiftSuspenders
> > >> and tell me if that solution (mostly the metadata, of course) is ok
> > >> with you - or propose changes.
> > >> If you've got a moment for that anytime soon, obviously.
>
> > >> cheers,
> > >> till
>
> > >> On Thu, Oct 1, 2009 at 16:31, Till Schneidereit <
> > tschneider...@gmail.com>
> > >> wrote:
> > >> > Hey Josh,
>
> > >> > I'll also try to implement ctor injection in SwiftSuspenders until
> > >> > tomorrow, maybe we can then compare results and try to unify metadata.
> > >> > I'll keep you posted on how it goes.
>
> > >> > cheers,
> > >> > till
>
> > >> > On Wed, Sep 30, 2009 at 23:56, Josh McDonald <j...@joshmcdonald.info>
> > >> > wrote:
> > >> >> Hi Till,
>
> > >> >> I haven't gotten too far into it yet, at the moment it's just some
> > >> >> failing
> > >> >> tests. That issue about metadata on constructors worries me though, I
> > >> >> hadn't
> > >> >> come across it. I'd definitely like to keep the metadata consistent
> > if
> > >> >> possible though, that's a great idea. Thursday's my "churn pending
> > >> >> business
> > >> >> admin BS" night, but I'll try and make a start on the impl tonight,
> > and
> > >> >> post
> > >> >> back my progress / ideas.
>
> > >> >> Cheers,
>
> > >> >> -Josh
>
> > >> >> 2009/10/1 Till Schneidereit <tschneider...@gmail.com>
> > >> > Till Schneidereit
> > >> > Schneidereit Link GbR
> > >> > technical concept, consulting, development
> > >> > Tel: +49 40 970 7848 1
>
> > >> --
> > >> Till Schneidereit
> > >> Schneidereit Link GbR
> > >> technical concept, consulting, development
> > >> Tel: +49 40 970 7848 1
>
> > > --
> > > "Therefore, send not to know For whom the bell tolls. It tolls for thee."
>
> > > Josh 'G-Funk' McDonald
> > Till Schneidereit
> > Schneidereit Link GbR
> > technical concept, consulting, development
> > Tel: +49 40 970 7848 1
>
> --
> "Therefore, send not to know For whom the bell tolls. It tolls for thee."
>
> Josh 'G-Funk' McDonald

Josh McDonald

unread,
Oct 7, 2009, 3:08:37 AM10/7/09
to smartyp...@googlegroups.com
Cool, thanks for the update :)

2009/10/7 Richard Lord <ric...@bigroom.co.uk>
  -  jo...@joshmcdonald.info

Till Schneidereit

unread,
Oct 7, 2009, 4:39:28 AM10/7/09
to smartyp...@googlegroups.com
Thanks Richard, that's great news!
Reply all
Reply to author
Forward
0 new messages