-
-
Notifications
You must be signed in to change notification settings - Fork 199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix avaje module #3426
Fix avaje module #3426
Conversation
@@ -68,7 +66,7 @@ public void install(Jooby application) throws Exception { | |||
e -> { | |||
final var key = e.getKey(); | |||
if (key.getName() == null) { | |||
beanScope.provideDefault(key.getType(), e::getValue); | |||
beanScope.provideDefault(key.getType(), e.getValue()::get); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
|
||
@Singleton | ||
@Path("") | ||
@InjectModule(requires = {JsonMapper.class, Config.class, String.class}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
never use Avaje Inject. Why do we need this line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Avaje Inject, the dependency graph is typically validated when the application compiles. As beans provided by Jooby Modules are registered at runtime, you must add @InjectModules(requires={String.class, <other Jooby Module Provided Bean ClassNames>…}) to inform the avaje processor that these beans are provided at runtime.
from https://jooby.io/#dependency-injection-avaje-inject-mvc-routes :)
@jknack
AvajeInjectModule seems doesn't work as expected, at least for me.
With a very basic example (reproduced in test c9c81fd) Jooby inner services injection fails with class cast exception, for example
JsonMapper
:I assume this is due to the fact that services already wrapped into lambda in
singletone()
jooby/jooby/src/main/java/io/jooby/internal/ServiceRegistryImpl.java
Line 61 in 03bb587
Hence, the default binding need to be changed to
beanScope.provideDefault(key.getType(), e.getValue()::get);
Also,
Config
binding was removed as it is already in service registry