I'd like to be able to load a Guice Module into the application context.
We currently use Ratpack and have quite a few projects that provide a Guice module that Ratpack adds in, which you can then retrieve from a handler. It achieves this by creating an implementation of its underlying Registry back by the Guice Injector. It then joins the two Registries together.
Not sure how this would be achieved at compile time. You could get the Injector and then loop through it's bindings and add them the the context.
Would be cool if this could be achieved.
For an example, there is the Spring implementation: https://github.com/spring-projects/spring-guice
Whilst I understand the motivation this won't be super high priority in the short term. However if you wish to advance it sooner we of course welcome contributions
I've never written anything like this before, so will need a few pointers.
So, if I annotated a method with @GuiceModule that simply returns the Guice module, would I then need an annotation processor that creates the Injector, then loops through its bindings and then adds them to Micronaut's DI. This is the bit I'm unsure about.
Any pointers?
Guice operates purely at runtime so I doubt anything can be done at the compiler level to integrate it. It would have to be something at runtime that uses registerSingleton on Micronaut's application context. I imagine that is how Spring's impl works
Actually what I really need is just a way to have Micronaut provide the Guice equivelant of bind(<interface>).to(<impl>) without having to create a factory. My implementations are already implemented with @Inject, I just need to provide the bindings.
I don't see us supporting this, but contributions welcome of course
Most helpful comment
Actually what I really need is just a way to have Micronaut provide the Guice equivelant of
bind(<interface>).to(<impl>)without having to create a factory. My implementations are already implemented with@Inject, I just need to provide the bindings.