Skip to content

Dependency Injection With Examples in Java, Ruby, and C#

Spend $50 to get a free movie!

ISBN-10: 193398855X

ISBN-13: 9781933988559

Edition: 2009

Authors: Dhanji R. Prasanna, David James Kelly

List price: $62.99
Blue ribbon 30 day, 100% satisfaction guarantee!
what's this?
Rush Rewards U
Members Receive:
Carrot Coin icon
XP icon
You have reached 400 XP and carrot coins. That is the daily max!

Description:

Dependency Injection is an in-depth guide to the current best practices forusing the Dependency Injection pattern-the key concept in Spring and therapidly-growing Google Guice. It explores Dependency Injection, sometimescalled Inversion of Control, in fine detail with numerous practical examples.Developers will learn to apply important techniques, focusing on their strengthsand limitations, with a particular emphasis on pitfalls, corner-cases, and bestpractices.This book is written for developers and architects who want to understandDependency Injection and successfully leverage popular DI technologies such asSpring, Google Guice, PicoContainer, and many others. The book exploresmany small…    
Customers also bought

Book details

List price: $62.99
Copyright year: 2009
Publisher: Manning Publications Co. LLC
Publication date: 9/7/2009
Binding: Paperback
Pages: 352
Size: 7.25" wide x 9.25" long x 1.00" tall
Weight: 1.320
Language: English

Dhanji R. Prasanna is an Enterprise Java consultant for technologies such as EJB3, JBI, JSF, Guice, Spring, HiveMind, and PicoContainer. He is a co-author of the Bean Validation (JSR-303), JAX-RS (JSR-311), Servlet 3.0 (JSR-315), and JavaServerFaces 2.0 (JSR-314) specifications. He is also co-author of the Java EE 6.0 (JSR-316) platform specification, which is the next edition of J2EE.

Preface
Acknowledgments
About this book
About the cover illustration
Dependency injection: what's all the hype?
Every solution needs a problem
Seeing objects as services
Pre-DI solutions
Construction by hand
The Factory Pattern
The Service Locator pattern
Embracing dependency injection
The Hollywood Principle
Inversion of Control vs. dependency injection
Dependency injection in the real world
Java
DI in other languages and libraries
Summary
Time for injection
Bootstrapping the injector
Constructing objects with dependency injection
Metadata and injector configuration
XML injection in Spring
From XML to in-code configuration
Injection in PicoContainer
Revisiting Spring and autowiring
Identifying dependencies for injection
Identifying by string keys
Limitations of string keys
Identifying by type
Limitations of identifying by type
Combinatorial keys: a comprehensive solution
Separating infrastructure and application logic
Summary
Investigating DI
Injection idioms
Constructor injection
Setter injection
Interface injection
Method decoration (or AOP injection)
Choosing an injection idiom
Constructor vs. Setter injection
The constructor pyramid problem
The circular reference problem
The in-construction problem
Constructor injection and object validity
Not all at once: partial injection
The reinfection problem
Reinjection with the Provider pattern
The contextual injection problem
Contextual injection with the Assisted Injection pattern
Flexible partial injection with the Builder pattern
Injecting Objects in sealed code
Injecting with externalized metadata
Using the Adapter pattern
Summary
Building modular applications
Understanding the role of an object
Separation of concerns (my pants are too tight!)
Perils of tight coupling
Refactoring impacts of tight coupling
Programming to contract
Loose coupling with dependency injection
Testing components
Out-of-container (unit) testing
I really need my dependencies!
More on mocking dependencies
Integration testing
Different deployment profiles
Rebinding dependencies
Mutability with the Adapter Pattern
Summary
Scope: a fresh breath of state
What is scope?
The no scope (or default scope)
The singleton scope
Singletons in practice
The singleton anti-pattern
Domain-specific scopes: the web
HTTP request scope
HTTP session scope
Summary
More use cases in scoping
Defining a custom scope
A quick primer on transactions
Creating a custom transaction scope
A custom scope in Guice
A custom scope in Spring
Pitfalls and corner cases in scoping
Singletons must be thread-safe
Perils of Scope-widening injection
Leveraging the Power of scopes
Cache scope
Grid Scope
Transparent grid computing with DI
Summary
From birth to death: object lifecycle
Significant events in the life of objects
Object creation
Object destruction (or finalization)
One size doesn't fit all (domain-Specific lifecycle)
Contrasting lifecycle scenarios: servlets vs. database connections
The Destructor anti-pattern
Using Java's Closeable interface
A real-world lifecycle scenario: stateful EJBs
Lifecycle and lazy instantiation
Customizing lifecycle with postprocessing
Customizing lifecycle with multicasting
Summary
Managing an object's behavior
Intercepting methods and AOP
A tracing interceptor with Guice
A tracing interceptor with Spring
How proxying works
Too much advice can be dangerous!
Enterprise use cases for interception
Transactional methods with warp-persist
Securing methods with Spring Security
Pitfalls and assumptions about interception and proxying
Sameness tests are unreliable
Static methods cannot be intercepted
Neither can private methods
And certainly not final methods!
Fields are off limits
Unit tests and interception
Summary
Best practices in code design
Objects and visibility
Safe publication
Safe wiring
Objects and design
On data and services
On Better encapsulation
Objects and concurrency
More on mutability
Synchronization vs. concurrency
Summary
Integrating with third-party frameworks
Fragmentation of DI solutions
Lessons for framework designers
Rigid configuration anti-patterns
Black box anti-patterns
Programmatic configuration to the rescue
Case study: JSR-303
Summary
Dependency injection in action!
Crosstalk: a Twitter Clone!
Crosstalk's requirements
Setting up the application
Configuring Google Sitebricks
Crosstalk's modularity and service coupling
The presentation layer
The HomePage template
The Tweet domain object
Users and sessions
Logging in and out
The persistence layer
Configuring the Persistence layer
The security layer
Tying up to the web lifecycle
Finally: up and running!
Summary
The Butterfly Container
Smarty Pants for Adobe Flex
index