Skip to content

springmonster/guice-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Github

Description

  • 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.

  1. No Bindings
  2. Bindings to itself
bind(TypeA.class).to(SubClassOfTypeA.class);

Images

![img.png](Object Graph.png) img.png img_1.png img_2.png

@BindingAnnotation vs @Named

  • @BindingAnnotation is a custom annotation that you create.
  • @Named is a built-in annotation that comes with Guice.
  • They can be used interchangeably.

@BindingAnnotation vs @Qualifier

  • @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 standard Qualifier annotation.
  • @Qualifier annotation. New code should use @Qualifier instead.

toInstance

  • bind(String.class).toInstance("jdbc:mysql://localhost/pizza");
  • bindConstant() is a shortcut for toInstance() for primitive types and strings.

Factory

Multibinding & MapBinder & SetBinder & Multibinder

AssistedInject

Eager

  • What's Eager in Guice?
  • Eager Singletons are instantiated when the Injector is created.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages