Google Guice

Google Guice is an open- source framework for Dependency Injection with Java. Guice was first published by Google in 2008 under the Apache license. As a first time framework makes Guice dependency injection using annotations. 2008 won the Jolt Award for the best framework.

Dependency Injection (DI) and Inversion of Control ( IoC )

Inversion of Control is a pattern in software development, in which programs do not generate their dependencies (ie, program parts or components from which they depend ) itself, but can be from outside " in type". This principle is generally no dependency injection, but is considerably simplified with Dependency Injection. Dependency Injection provides in this respect that the components are not generated by the user, but a " Injector " (the name in Google Guice ) is generated. This injector can generate all necessary " subcomponents " concrete objects and thus also provide the requested often complex object. For this to be used concrete classes are given (for example, interfaces ) for the injector. This is done via so-called modules in Google Guice.

Modules in Google Guice

Modules in Guice summarize the dependencies to use a particular " subject area " together. How far this " issue " is taken, is left to the individual programmer and can vary greatly from software project to software project. Together the modules is that they (often abstract ) dependencies in the project mapping or concrete classes to be used to "bind ". Thus, e.g. be determined that an object of type "Network Mail Sender " is injected at each location where a type of interface " Mail Sender " will be used. The central mapping of types to be used in the modules of the injectors, the objects actually used can be replaced very easily. Thus, for example very simple mock objects (eg MailSenderMock ) for the interface " Mail Sender " are bound in unit tests that simulate the function of the mail forwarding and thus make easy, quick, independent and stable test cases possible.

Scopes

For the objects to be used can be determined how long the objects once created will be "cached " (ie reused) to be. These details are mentioned in Guice "Scope". The most popular scopes are the " default scope" ( no explicit scope specification), in which each request type, a new object is created, or the " singleton -scope " in which program-wide - controlled by the injector - only an object of this type exists. The scopes can be expanded for its own purposes.

272822
de