Dependency Injection
Design patterns using Spring and Guice
Dhanji R. Prasanna
Foreword by Bob Lee
  • July 2009
  • ISBN 9781933988559
  • 352 pages
  • printed in black & white

Transcends implementation details...covers customary and effective use of DI.

Bob Lee, Software Engineer, Google Inc. and Creator of Guice

In object-oriented programming, a central program normally controls other objects in a module, library, or framework. With dependency injection, this pattern is inverted—a reference to a service is placed directly into the object which eases testing and modularity. Spring or Google Guice use dependency injection so you can focus on your core application and let the framework handle infrastructural concerns.

Dependency Injection explores the DI idiom in fine detail, with numerous practical examples that show you the payoffs. You'll apply key techniques in Spring and Guice and learn important pitfalls, corner-cases, and design patterns.

Table of Contents detailed table of contents



about this book

about the cover illustration

1. Dependency injection: what’s all the hype?

1.1. Every solution needs a problem

1.2. Pre-DI solutions

1.3. Embracing dependency injection

1.4. Dependency injection in the real world

1.5. Summary

2. Time for injection

2.1. Bootstrapping the injector

2.2. Constructing objects with dependency injection

2.3. Metadata and injector configuration

2.4. Identifying dependencies for injection

2.5. Separating infrastructure and application logic

2.6. Summary

3. Investigating DI

3.1. Injection idioms

3.2. Choosing an injection idiom

3.3. Not all at once: partial injection

3.4. Injecting objects in sealed code

3.5. Summary

4. Building modular applications

4.1. Understanding the role of an object

4.2. Separation of concerns (my pants are too tight!)

4.3. Testing components

4.4. Different deployment profiles

4.5. Summary

5. Scope: a fresh breath of state

5.1. What is scope?

5.2. The no scope (or default scope)

5.3. The singleton scope

5.4. Domain-specific scopes: the web

5.5. Summary

6. More use cases in scoping

6.1. Defining a custom scope

6.2. Pitfalls and corner cases in scoping

6.3. Leveraging the power of scopes

6.4. Summary

7. From birth to death: object lifecycle

7.1. Significant events in the life of objects

7.2. One size doesn’t fit all (domain-specific lifecycle)

7.3. A real-world lifecycle scenario: stateful EJBs

7.4. Lifecycle and lazy instantiation

7.5. Customizing lifecycle with postprocessing

7.6. Customizing lifecycle with multicasting

7.7. Summary

8. Managing an object’s behavior

8.1. Intercepting methods and AOP

8.2. Enterprise use cases for interception

8.3. Pitfalls and assumptions about interception and proxying

8.4. Summary

9. Best practices in code design

9.1. Objects and visibility

9.2. Objects and design

9.3. Objects and concurrency

9.4. Summary

10. Integrating with third-party frameworks

10.1. Fragmentation of DI solutions

10.2. Lessons for framework designers

10.3. Programmatic configuration to the rescue

10.4. Summary

11. Dependency injection in action!

11.1. Crosstalk: a Twitter clone!

11.2. Setting up the application

11.3. Configuring Google Sitebricks

11.4. Crosstalk’s modularity and service coupling

11.5. The presentation layer

11.6. The persistence layer

11.7. The security layer

11.8. Tying up to the web lifecycle

11.9. Finally: up and running!

11.10. Summary

Appendix A: The Butterfly Container

Appendix B: SmartyPants for Adobe Flex


What's inside

  • How to apply it (Understand it first!)
  • Design patterns and nuances
  • Spring, Google Guice, PicoContainer, and more
  • How to integrate DI with Java frameworks

About the reader

Readers need a working knowledge of Java but no prior experience with DI is assumed.

About the author

Dhanji R. Prasanna is a Google software engineer who works on Google Wave and represents Google on several Java expert groups. He contributes to Guice, MVEL, and other open source projects.

placing your order...

Don't refresh or navigate away from the page.
print book $34.99 $49.99 pBook + eBook + liveBook
Additional shipping charges may apply
Dependency Injection (print book) added to cart
continue shopping
go to cart

eBook $27.99 $39.99 3 formats + liveBook
Dependency Injection (eBook) added to cart
continue shopping
go to cart

Prices displayed in rupees will be charged in USD when you check out.

FREE domestic shipping on three or more pBooks