ef-labs / vertx-guice

Create Vert.x Modules and Verticles with dependency injection using Guice
MIT License
59 stars 24 forks source link

Pass Vertx and Container to Binder #1

Closed tipok closed 8 years ago

tipok commented 10 years ago

passing Vertx and Container parameters to binder constructor if finds matching constructor

adrianluisgonzalez commented 10 years ago

Can you describe the scenario where you need Vertx/Container instances in your bootstrap binder? The VertxBinder already provides the Vertx and Container instances for injection to classes.

pmvilaca commented 10 years ago

Hi guys,

I'm also trying to use this project in order to try to inject the Vertx object inside an aspect but the Binder isn't working because we can't instantiate a new instance that doesn't have a constructor without arguments. I think that this commit is the solution for that problem.

pmvilaca commented 10 years ago

Btw, I think that you should change the description of this pull request to clarify that it's a bug

adrianluisgonzalez commented 10 years ago

Got it, you are using guice interceptors and that is why you need the vertx/container instances in your bootstrap binder.

In general, my preference is to avoid the try/catch approach to programming. I would probably use getConstructors() to see if there is a constructor that has a signature I could use.

Another approach would be adding an interface with an init(Vertx vertx, Container container) method. I feel that is more explicit than a "special" constructor signature. If that doesn't work, can you add information to the README.md about the constructor signatures that are supported?

pmvilaca commented 10 years ago

No, I'm using aspectj directly. I was just trying to use guice to inject some dependencies inside aspects (e.g. EventBus). Although, I wasn't able to do that. The aspect that was being created inside the (guice) module wasn't being used. Any idea how can I solve this problem?

adrianluisgonzalez commented 10 years ago

Do you have any sample code and stack trace?

adrianluisgonzalez commented 8 years ago

Closing as Container no longer exists and the current Context can be accessed via Vertx.currentContext() .