Qt dependency injection

Mark Kretschmann kretschmann at kde.org
Wed Sep 9 14:08:17 CEST 2009


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 :)

-- 
Mark Kretschmann
Amarok Developer
www.kde.org - amarok.kde.org


More information about the Amarok-devel mailing list