Subject: Re: Playing Better With Dependency Injection
From: Robert Burrell Donkin <[email-masked]>
To: Excalibur Developers List <[email-masked]>
Date: Wed, 19 Aug 2009 11:40:46 +0100
List-Id: "Excalibur Developers List" <dev.excalibur.apache.org>

On Wed, Aug 12, 2009 at 11:43 AM, J Aaron Farr<[email-masked]> wrote:
> On Tue 11 Aug 2009 22:36, Leo Simons <[email-masked]> wrote:
>
>> On Tue, Aug 11, 2009 at 10:44 AM, Robert Burrell
>> Donkin<[email-masked]> wrote:
>>> avalon is an IoC container but is mainly tooled for composition using
>>> the Service Locator pattern (Servicable, ServiceManager). these days,
>>> dependency injection (whether through setters or constructors) is much
>>> more popular. so, i think we should add setters, getters and
>>> constructors so that Servicable components can also play well in DI
>>> containers.
>>>
>>> opinions?
>>> objections?
>>
>> The avalon lifecycle interfaces have this nice container-provided
>> guarantee that after the last few of them have been called, you know
>> your component is in a fully initialized state, fully aware of its
>> surroundings, and that those surroundings won't change after that
>> (unless you implement Re* which is again a set of specific contracts).
>>
>> While I think its quite alright to add support for dependency
>> injection, I think it is important to keep this
>> guaranteed-to-be-initialized-at-an-obvious-point-in-time contract
>> intact. That's trivially true if you use constructor DI, but not so
>> much so if you add setters, so I'd rather not see any setter
>> injection.
>
> I agree with Leo on this one.  If there's a way we can support running
> Avalon services in setter-style DI containers, then that's great.  But
> I'd also want to make sure that all the promises we've made about
> lifecycle support are maintained.

IMHO lifecycle guarantees need to be enforced by the container and are
independent of the injection strategy

setter injections (and dynamic service locators) typically need to
perform lifecycle management, so these just need to be bridged
correctly.

for example, the avalon-spring bridge from jamesland adapts spring
lifecycle events into avalon ones. so, even though the spring
injection is setter based, the dependent components will be injected
before the appropriate avalon lifecycle methods are called.

i would expect that the dynamic approach to service provision adopted
by OSGi would mean that an OSGi enabled avalon service would need to
call appropriate lifecycle methods to manage services coming and
going.

- robert

---------------------------------------------------------------------
To unsubscribe, e-mail: [email-masked]
For additional commands, e-mail: [email-masked]