Java Vert.x with Dependency Injection

1,421 views
Skip to first unread message

Zolf

unread,
Jan 13, 2022, 9:39:48 AM1/13/22
to vert.x
Hi there,

I want to know does the community recommend the need to use DI with Java Vertx or I can create objects using simple constructor. Any feedback will be greatly appreciated.

regards
Zolf

Nicolas Le Bas

unread,
Jan 13, 2022, 11:00:46 AM1/13/22
to ve...@googlegroups.com

Hi,

I suppose your question derives from a confusion between DI (as in SOLID principles) and DI frameworks (like Spring).

I believe DI as a programming technique should always be used, because it allows mocking dependencies and is a cornerstone of unit testing.

It could be simple constructor injection without a framework. Whether the use of a framework like Spring will help with your project or not, that's independent from Vert.x .

Hope this helps,

Nic

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/fe1ad03b-2790-4f96-8c39-ab721188f2f2n%40googlegroups.com.

andriusk

unread,
Jan 14, 2022, 6:32:19 AM1/14/22
to vert.x
Hi,


the author discusses this topic and shows demo Vertx with Micronaut DI. Other available options are discussed in the same article as well. 

Micronaut documentation claims that their DI does not rely on runtime reflection and proxies, so it gives better startup time and performance. 
Also, Micronaut's DI can be used completely independently of Micronaut framework for whatever application type you wish to build.

Quarkus framework uses Vertx components and it is possible to use Vertx directly within the framework. Quarkus also supports DI https://quarkus.io/guides/cdi

Thanks
Andrius

hantsy bai

unread,
Jan 14, 2022, 6:55:30 AM1/14/22
to ve...@googlegroups.com
It is easy to integrate Spring and Weld(CDI) with Vertx and provides DI service.
Check my example:

Hantsy Bai

Self-employed consultant, fullstack developer, agile coach

GitHub: https://github.com/hantsy

Twitter: https://twitter.com/@hantsy

Medium: https://medium.com/@hantsy


Reply all
Reply to author
Forward
0 new messages