Runtime phase

We will now be able to utilize the injector we made during the start-up phase to inject objects and examine our bindings. Guice's runtime phase consists of an injector which contains a few bindings:

The preceding diagram defines the components of each binding. Each key uniquely recognizes each binding. The key consists of a type, which the client depends on, and an annotation, which is optional. An annotation could be used to distinguish a couple of bindings of the same type.

Every single binding has a provider, which gives an instance of the mandatory type. We may offer a class, and Guice will make instances of it for us. We might give Guice an instance of the type for binding the class. Guice can inject dependencies if we provide our own provider.

By default, no bindings have a scope; but it's optionally available, and for each injection, Guice creates a new instance, which is similar to Spring Prototype. Guice also provides a facility to define a custom scope to govern whether or not Guice makes a new instance. In this case, we can make one instance per HttpSession.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.129.70.185