hmm.... did I say that? Really it's:

1) Setter-injection supports circular dependencies

2) Constructor-arg-injection lends for more testable code because one
cannot create the object without first having its dependencies on hand
to supply to the constructor.

The only thing I truly recommend is that you choose an approach and
stick with it. Obviously there's pros/cons to each.

-Dave



On 7/18/06, Teddy Payne <[EMAIL PROTECTED]> wrote:
Too funny!  Sean you just hit the poor guy with a huge bat.  he probably
went "Owe! WTF Sean?!"

Setter injection is the use of the property method.  Constructor injection
is the use of constructor-arg.

Teddy


On 7/18/06, Sean Corfield <[EMAIL PROTECTED]> wrote:
> On 7/18/06, Perry Woodin <[EMAIL PROTECTED]> wrote:
> > After setting this up, I went back to look at some of the examples that
ship
> > with ColdSpring and noticed that <property> seems to be used in favor of
> > <constructor-arg>.  Is there a general rule for when to use one over the
> > other?
>
> Dave Ross, in his presentation at CFUNITED, said "favor setter
> injection over constructor injection".
>
> Setter injection supports circular dependencies, constructor injection
> does not (pretty much by definition).
>
> It's better (IMO) to have objects constructed with just the data they
> need in order to be usable and then inject everything else. In
> general, I only use constructor injection for simple scalar values
> (e.g., strings) and use setter injection for more complex properties.
> --
> Sean A Corfield -- http://corfield.org/
> Got frameworks?
>
> "If you're not annoying somebody, you're not really alive."
> -- Margaret Atwood
>
>



--
<cf_payne />

Reply via email to