Constructor injection in SVN?

2 views
Skip to first unread message

Greg

unread,
May 25, 2009, 1:17:41 AM5/25/09
to Smartypants IOC
Hi All,

The code version in SVN trunk is 1.0 which does not include
constructor injection.

Can I get my hands on a version that does have constructor injection?

Josh McDonald

unread,
May 25, 2009, 1:26:21 AM5/25/09
to smartyp...@googlegroups.com
Hi Greg,

Currently there is no version with constructor injection. It *is* a planned feature, just not implemented yet. If you have any thoughts on the syntax you'd like to see, let me know. Besides that, it will turn up eventually :)

Cheers,
-Josh

2009/5/25 Greg <gmcc...@hotmail.com>



--
"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/

Bjorn Schultheiss

unread,
May 25, 2009, 1:28:43 AM5/25/09
to smartyp...@googlegroups.com
what a shame

--
Regards,


Bjorn

Josh McDonald

unread,
May 25, 2009, 1:35:28 AM5/25/09
to smartyp...@googlegroups.com
There's a lot of things I'd like to be able to do, but some like constructor injection require some thinking (and time), and others just can't be done yet because of the AVM2 limitations.

To be honest, the main reason it's not built yet is I haven't needed it, although it's definitely a nice-to-have. The only real problem is cooking up a nice syntax for the annotations, and the fact that parameter names aren't available to runtime code.

-Josh

2009/5/25 Bjorn Schultheiss <bjorn.sc...@gmail.com>

Greg McCreath

unread,
May 25, 2009, 1:37:11 AM5/25/09
to smartyp...@googlegroups.com

Hi Josh,

Thanks for the quick response.  I saw in the forums discussion that you had 'hacked' one together.  At this point, I'm not looking to use anything in production, just checking things out.

Greg.


Date: Mon, 25 May 2009 15:26:21 +1000
Subject: Re: Constructor injection in SVN?
From: jo...@joshmcdonald.info
To: smartyp...@googlegroups.com

Find car news, reviews and more Looking to change your car this year?

Josh McDonald

unread,
May 25, 2009, 1:48:57 AM5/25/09
to smartyp...@googlegroups.com
The patch in question is here:

http://pastie.org/449817

But it's not by me, and I haven't had a chance to play with it yet unfortunately. I've got a lot of stuff on at the moment, so I'm not currently adding features to the injector. I will fix bugs that crop up though, constructor injection just isn't high on my priority list as it's never going to be "nice" under AVM2/AS3.

What are you trying to do that you find you need constructor injection?

-Josh

2009/5/25 Greg McCreath <gmcc...@hotmail.com>

Bjorn Schultheiss

unread,
May 25, 2009, 1:52:06 AM5/25/09
to smartyp...@googlegroups.com
Using Constructor Injection over Setter Injection allows you to specify an Instantiation order.


http://misko.hevery.com/2009/02/19/constructor-injection-vs-setter-injection/


Greg and I work together.
--
Regards,


Bjorn

Greg McCreath

unread,
May 25, 2009, 1:53:43 AM5/25/09
to smartyp...@googlegroups.com

"Using Constructor Injection over Setter Injection allows you to specify an Instantiation order."

yes, that.

Greg.


Date: Mon, 25 May 2009 15:52:06 +1000

Subject: Re: Constructor injection in SVN?

Check out the new Windows Live Messenger Looking for a fresh way to share your photos?

Greg McCreath

unread,
May 25, 2009, 2:04:18 AM5/25/09
to smartyp...@googlegroups.com

Thanks.  Appreciated.

Greg.


Date: Mon, 25 May 2009 15:48:57 +1000

Find out how with Windows Live! Want to stay on top of your life online?

Josh McDonald

unread,
May 25, 2009, 2:17:40 AM5/25/09
to smartyp...@googlegroups.com
Constructor injection doesn't resolve circular dependencies, but simply keeps you from creating them, unless you have run-time proxy creation, which is how Guice does it. Unfortunately until Maxim Porges gets Loom-AS3 off the ground (which looks to be soon) proxy generation isn't an option in Flash.

As a rule, I agree that constructor injection is a better option. But a lot of the things that make it attractive in Java aren't available in Flash: Run-time introspection of parameter names, parameter annotations, constructor overloading, final vars, etc.

When Loom is stable and complete enough for me to build on, and I've got some other changes out of the way I intend to build into SP-IOC the ability to group rules into sets, and the injector will go through the rules and make sure they don't specify anything illegal such as an unresolveable dependency, and build proxies to get around the circular dependency problem.

First we'll need annotations based on argument position, such as:

[Inject(position="0", name="foo")]
[Inject(position="1", name="bar")]
function ClassWithConstructorInjection(s1:SomeClass, s2:AnotherClass)
{
  //;
}

Which doesn't seem so bad at first, but due to the way ASDoc works (you can document annotations), any documentation will have to go between the last annotation and the constructor method. If you've got 3 paragraphs of documentation between the Injection annotations and your constructor, you're far more likely to forget to change one when you change the other.

None of these are of course show-stoppers, I'm just trying to elaborate on why I think it needs more thought put into it before I just jump in.

Bjorn Schultheiss

unread,
May 25, 2009, 2:28:11 AM5/25/09
to smartyp...@googlegroups.com
Regarding circular dependency there is this post.

http://misko.hevery.com/2008/08/01/circular-dependency-in-constructors-and-dependency-injection/
--
Regards,


Bjorn

Greg McCreath

unread,
May 25, 2009, 2:29:33 AM5/25/09
to smartyp...@googlegroups.com

Thanks Josh,

Yes, I understand the way that Guice does its thing, and no, I didn't expect it to be easy in AS3!

So I guess you can achieve the same sort of thing in a noddy 'manual fashion (no constructor injection at all) by doing something like:

Say 'A' has a dependency on 'B' which has dependencies (via a two param constructor) on 'C' & 'D'.

In the constructor of A, you are creating a C and D (using the injector to decide which impls to use and intantiate them), and then feeding those into the constructor on B (and then probably doing a manual inject on B to be safe).

Something like that?

Not great, but ...

Greg.


Date: Mon, 25 May 2009 16:17:40 +1000

Josh McDonald

unread,
May 25, 2009, 2:32:21 AM5/25/09
to smartyp...@googlegroups.com
Yeah I read that, it didn't clear anything up for me :) Now, whatever methods that used to be in A and needed to call B have been moved to C, but they can no longer call anything that's in A, because C can't rely on A.

It's all very hand-wavey, and just illustrates the insanity that surrounds most OOP implementations sometimes.

-Josh

2009/5/25 Bjorn Schultheiss <bjorn.sc...@gmail.com>
Regarding circular dependency there is this post.
Reply all
Reply to author
Forward
0 new messages