vertx-guice

Enable Verticle dependency injection in Vert.x using Guice.

License

License

Categories

Categories

GUI User Interface Guice Application Layer Libs Dependency Injection
GroupId

GroupId

com.intapp
ArtifactId

ArtifactId

vertx-guice
Last Version

Last Version

1.0
Release Date

Release Date

Type

Type

jar
Description

Description

vertx-guice
Enable Verticle dependency injection in Vert.x using Guice.
Project URL

Project URL

https://github.com/intappx/vertx-guice
Project Organization

Project Organization

Intapp Inc.
Source Code Management

Source Code Management

https://github.com/intappx/vertx-guice

Download vertx-guice

How to add to project

<!-- https://jarcasting.com/artifacts/com.intapp/vertx-guice/ -->
<dependency>
    <groupId>com.intapp</groupId>
    <artifactId>vertx-guice</artifactId>
    <version>1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.intapp/vertx-guice/
implementation 'com.intapp:vertx-guice:1.0'
// https://jarcasting.com/artifacts/com.intapp/vertx-guice/
implementation ("com.intapp:vertx-guice:1.0")
'com.intapp:vertx-guice:jar:1.0'
<dependency org="com.intapp" name="vertx-guice" rev="1.0">
  <artifact name="vertx-guice" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.intapp', module='vertx-guice', version='1.0')
)
libraryDependencies += "com.intapp" % "vertx-guice" % "1.0"
[com.intapp/vertx-guice "1.0"]

Dependencies

compile (2)

Group / Artifact Type Version
io.vertx : vertx-core jar 3.2.1
com.google.inject : guice jar 4.0

test (5)

Group / Artifact Type Version
junit : junit jar 4.11
org.assertj : assertj-core-java8 jar 1.0.0m1
org.mockito : mockito-core jar 1.10.19
io.vertx : vertx-core jar 3.2.1
io.vertx : vertx-rx-java jar 3.2.1

Project Modules

There are no modules declared in this project.

vertx-guice

Enable Verticle dependency injection in Vert.x using Guice.

Build Status Code Coverage Maven Central

It is designed to use single injector per Vert.x instance. It means that `Singleton' scope is supported and works as expected. This was the main reason to implement this library instead of using vertx-guice library from English Town.

What does it provide

  • GuiceVerticleFactory which uses Guice for verticle creation. To be used, it should be registered in Vertx and verticle should be deployed with java-guice: prefix.
  • GuiceVertxLauncher which extends default vert.x launcher. It performs all necessary work related to the creating single injector per Vert.x instance, registering GuiceVerticleFactory. To register application specific dependencies, you can also create a sub-class of GuiceVertxLauncher and use it to start your application.
  • GuiceVertxDeploymentManager which implements convenient methods to deploy verticles programmatically by specified class using GuiceVerticleFactory factory.
  • VertxModule which contains binding for vertx itself and it's cached objects like EventBus, FileSystem, SharedData.

How to use

Several examples were added which covers main scenarios of the adding dependency injection support.

Vert.x Launcher

Shows the way to use GuiceVertxLauncher to run application with registering application specific modules and deploying verticle with injecting dependencies.

Basically it covers the following:

  • Extending GuiceVertxLauncher to register application specific modules
  • Customized run gradle task which deploys verticle with constructor dependency injection.

Note some of the useful information about Vert.x launcher and gradle configuration can be found in vertx 3.0 examples.

Creating and running Vert.x manually

Example which shows the following:

  • Creating vertx manually in application main entry point
  • Creating single injector with Vertx and application specific modules
  • Registering 'GuiceVerticleFactory'.
  • Deploying verticle programmatically which uses 'GuiceVerticleFactory'
Using dependency injection with Vert.x services

There is an Vert.x Service Proxy library which allows to develop less verbosity code for asynchronous verticles (which works over event bus). This example shows the following:

  • Particular the same stuff from manual example with addition that Vertx service concept is used.
  • Dependency injection in service itself
  • Hiding service registration and proxy creation by using Guice Provider concept
  • Using of the service via injected generated proxy in verticle
  • Gradle configuration

TO-DO

  • Request Scope Support (if there will be a real use case for this)
com.intapp

Intapp X

Versions

Version
1.0