Chapter 11. Dependency injection in action!

 

This chapter covers:

  • Building a complete web application from scratch
  • Seeing DI principles in a working application
  • Applying useful design patterns
  • Solving many common problems

“A computer lets you make more mistakes faster than any invention in human history—with the possible exceptions of handguns and tequila.”

Mitch Radcliffe

In this chapter we’ll put all of the things you’ve learned so far in this book into practice in a real, working application. While there probably aren’t enough pages to demonstrate a large enterprise application, we’ll look at a succinct application that gives us all the salient features of a broader program.

This program will start from bootstrapping the injector in a web application and walk through designing services for persistence, transactions, and user interactivity. We’ll also show how to apply some useful design patterns (such as the Provider pattern from chapter 5) and ways to properly leverage scope, lifecycle, and interception (AOP).

Let’s start by defining what this program will be.

11.1. Crosstalk: a Twitter clone!

I’ve chosen to do a simple, trivial clone of the popular microblogging service Twitter. (This isn’t in the least bit because I spend large chunks of my day on Twitter!) While I was writing this chapter, I thought crosstalk was cool code name.

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