- Github
- Description
- Images
- @BindingAnnotation vs @Named
- @BindingAnnotation vs @Qualifier
- toInstance
- Factory
- If TypeA is an interface, then, we must have bindings to concrete classes.
bind(TypeA.class).to(ConcreteTypeA.class);
- If TypeA is a concrete class, then, we can bind it to itself.
- No Bindings
- Bindings to itself
bind(TypeA.class).to(SubClassOfTypeA.class);
- @BindingAnnotation is a custom annotation that you create.
- @Named is a built-in annotation that comes with Guice.
- They can be used interchangeably.
- @BindingAnnotation is a custom annotation that you create.
- @Qualifier is a built-in annotation that comes with Guice.
- They can be used interchangeably.
- Older code may still use Guice
BindingAnnotation
in place of the standardQualifier
annotation. @Qualifier
annotation. New code should use@Qualifier
instead.
bind(String.class).toInstance("jdbc:mysql://localhost/pizza");
- bindConstant() is a shortcut for toInstance() for primitive types and strings.
- medium
- stackoverflow
- https://stackoverflow.com/questions/17669413/can-guice-automatically-create-instances-of-different-classes-based-on-a-paramet
- https://medium.com/@AlexanderObregon/guice-multibindings-leveraging-the-power-of-set-and-map-bindings-6bea4ee247fa
- https://github.com/google/guice/wiki/Multibindings
- https://www.youtube.com/watch?v=3uAR5sFgh2A&list=PLKiN3faYVq89TjVuba-F62_nKBpcFdOWz&index=2
- Github
- https://toshiyakomoda.medium.com/guice-assistedinject-f49b29105651
- Dagger
- What's Eager in Guice?
- Eager Singletons are instantiated when the Injector is created.