Dependency Injection with Guice | OCI
In the past few years, the Java community has embraced the principles of Dependency Injection (DI). DI frameworks such as Spring are in widespread use. Recently, a new DI framework called Guice (pronounced "juice") has drawn attention. As opposed to more comprehensive frameworks like Spring, Guice functionality is limited almost exclusively to Dependency Injection (some AOP support representing the "almost"). Guice also differs from Spring, defining wiring with Java as opposed to XML.
Guice Basics
Guice utilizes a combination of annotations and Java code to define where injection occurs and what is injected. Guice is therefore limited to use with Java 5 or later.
In order to demonstrate Guice, we will create a simple example of an order execution system comprised of several services dependent upon one another in various ways. These dependencies will be resolved by Guice (effectively "wiring" the services together). The core service is the OrderService
, with an implementation below which has been "Guiced".
Read full article from Dependency Injection with Guice | OCI
No comments:
Post a Comment