Had a project in hands where I needed for the injected instances to have access to the verticle's config.
I think this feature might be usefull for more people and worth of adding to the vertx-guice. :)
Example:
vertx.deployVerticle(GuiceVerticleFactory.PREFIX + ":" + "ExampleVerticle",
new DeploymentOptions().setConfig(new JsonObject().put(GuiceVerticleFactory.GUICE_CONFIG, new JsonObject().put("api", new JsonObject().put("host", "localhost").put("port", 81)))),
someHandler);
Injecting a configuration to an instance can be done using the Named annotation containing the "path" to the needed configuration, in the SomeClient class below config will contain a JsonObject with "{ host : "localhost", port: 81}". If you need the whole configuration JsonObject just use a Named annotation containing "config", in this case it will be "{ api: { host : "localhost", port: 81} }".
public class SomeClient {
@Inject
public SomeClient(Vertx vertx, @Named("config.api") JsonObject config) {
//Some initialisation code
}
}
Injecting SomeClient into a Verticle
public class ExampleVerticle extends AbstractVerticle {
@Inject
public ExampleVerticle(SomeClient client) {
}
}
Had a project in hands where I needed for the injected instances to have access to the verticle's config.
I think this feature might be usefull for more people and worth of adding to the vertx-guice. :)
Example:
Injecting a configuration to an instance can be done using the Named annotation containing the "path" to the needed configuration, in the SomeClient class below config will contain a JsonObject with "{ host : "localhost", port: 81}". If you need the whole configuration JsonObject just use a Named annotation containing "config", in this case it will be "{ api: { host : "localhost", port: 81} }".
Injecting SomeClient into a Verticle