[Interest] dependency injection

Alexandre Pretyman alexandre.pretyman at gmail.com
Wed Nov 14 19:03:05 CET 2012


Hi Yunior,

I've been doing DI by hand on small projects for university and it has
been working well. Just pass all the dependencies on the class
constructor and you are done. Avoid using setters dependencies because
you don't want to let broken objects being constructed in the first
place.

If you are using DI to ease unit testing, like I was, separate your
projects with the SUBDIRS template, have your components generate a
LIB project, and instantiate your objects in another project, like an
APP project.
Then you can have separated test projects instantiating your objects
passing mock dependencies to fulfill test cases.

If you really want the "Injector" element, I guess you could use
templates as factories to instantiate<YourType>() and specialize the
template with the object configuration by code inside the template
body. The template body would be analogous to the XML configuration,
but hardcoded. You could have different templates definitions for your
main app and for your tests. I have not tried it myself, but should
work.

As other's noted, you might to read
http://en.wikipedia.org/wiki/Dependency_injection because that link
explains the design pattern.


On Wed, Nov 14, 2012 at 11:45 AM, Yunior Bauta <ypenton at uci.cu> wrote:
> What 's the more used dependency injection framework in Qt, Any sample.
>
> 10mo. ANIVERSARIO DE LA CREACION DE LA UNIVERSIDAD DE LAS CIENCIAS INFORMATICAS...
> CONECTADOS AL FUTURO, CONECTADOS A LA REVOLUCION
>
> http://www.uci.cu
> http://www.facebook.com/universidad.uci
> http://www.flickr.com/photos/universidad_uci
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest



-- 
Alexandre Pretyman



More information about the Interest mailing list