Qt dependency injection
Maximilian Kossick
maximilian.kossick at googlemail.com
Wed Sep 9 14:48:28 CEST 2009
On Wed, Sep 9, 2009 at 2:08 PM, Mark Kretschmann<kretschmann at kde.org> wrote:
> On Tue, Sep 8, 2009 at 9:11 AM, Maximilian
> Kossick<maximilian.kossick at googlemail.com> wrote:
>> after reading Jos' blog on singletons
>> (http://www.kdedevelopers.org/node/4059, although I disagree with his
>> conclusion), and knowing that this is basically a solved problem in
>> the Java world thanks to dependency injection containers like Spring,
>> I've started to wonder why Qt does not provide a DI container itself,
>> which should be possible using QObjects.
>>
>> A bit of googling showed: there actually is one:
>> http://qtioccontainer.sourceforge.net
>>
>> The only problem is that the last update was three years ago...
>>
>> This is just a heads up that I'm going to play with it on one of the
>> next weekends. A major advantage that this could give us is that we
>> could get replace all those ::instance() methods with code that looks
>> up the object in the application context, and actually returns a mock
>> object for tests by defining a special application context for the
>> tests. Using that approach, we could start to write tests for major
>> components that are unfortunately untestable at the moment in my
>> opinion.
>
> If it works like I think (had to read up on the technique) this could
> be interesting indeed. Especially if it can fix the issue with
> unpredictable destruction order of singletons that has bitten us
> before, which also seems to be Jos's main problem. I also disagree
> with his conclusion though :)
No, this does not fix the unpredictable order of destruction. The
classes will be destroyed by the DI container, but I don't think there
are any guarantees about that order of destruction (but you can
guarantee that it will happen before QApplication shuts down). That's
where Qt 4.6 and QStateMachine come in :)
> --
> Mark Kretschmann
> Amarok Developer
> www.kde.org - amarok.kde.org
>
More information about the Amarok-devel
mailing list