没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Robbie Vanbrabant
Google
Guice
Agile Lightweight Dependency
Injection Framework
EMPOWERING PRODUCTIVITY FOR THE JAVA
™
DEVELOPER
Google Guice: Agile Lightweight
Dependency Injection Framework
Dear Reader,
This book welcomes you to the world of Google Guice (pronounced “juice”), the latest
and greatest dependency injection framework that fully exploits all modern Java
™
features. One step at a time, this book will help turn any XML-spitting programmer
into a true Guice master, or a “Bob,” as I like to say.
I’m particularly proud of this book’s coverage. To make sure that nobody gets left
behind, I start out with an introduction to dependency injection concepts. From
there, you will learn how Guice makes your life easier, and you’ll gradually become a
Guice expert. Beyond that, I also devoted two chapters to web application development
with Struts 2 and Wicket, including content on how to organize your application and
how to use Warp Persist, a popular Guice extension, to access your data using the Java
Persistence API and Hibernate.
Writing this book was not an easy task, so in addition to Apress, I’d like to thank
some people in particular. First, I would like to thank Dhanji R. Prasanna for referring me
to Apress to write this book. He has also done a fantastic job as my technical reviewer.
I’d also like to thank Bob Lee, the inventor of Guice, who kindly answered all of my
questions and inspired much of the content in Chapter 8. Finally, a big thank you goes
out to my friends, my parents, my brother, and anyone who believes in me; you are
the people who put the smile on my face.
Now, put on your Batman or Catwoman costume; open up a bottle of wine; pick up
this book; and put your feet up. Be a Java hero, and may Guice help you on your way.
Just don’t forget to send me a picture of you in that getup.
Robbie Vanbrabant
http://garbagecollected.org
Vanbrabant
Google Guice
Apress’s firstPress series is your source for understanding cutting-edge technology. Short, highly
focused, and written by experts, Apress’s firstPress books save you time and effort. They contain
the information you could get based on intensive research yourself or if you were to attend a
conference every other week—if only you had the time. They cover the concepts and techniques
that will keep you ahead of the technology curve. Apress’s firstPress books are real books, in your
choice of electronic or print-on-demand format, with no rough edges even when the technology
itself is still rough. You can’t afford to be without them.
this print for content only—size & color not accurate spine = 0.408" 192 page count
User level:
Intermediate
www.apress.com
java.apress.com
SOURCE CODE ONLINE
180
PAGES
Available as a
PDF Electronic Book
or Print On Demand
About firstPress
Apress's firstPress series is your source for understanding cutting-edge technology. Short,
highly focused, and written by experts, Apress's firstPress books save you time and effort. They
contain the information you could get based on intensive research yourself or if you were to
attend a conference every other week—if only you had the time. They cover the concepts and
techniques that will keep you ahead of the technology curve. Apress's firstPress books are real
books, in your choice of electronic or print-on-demand format, with no rough edges even when
the technology itself is still rough. You can't afford to be without them.
Google Guice: Agile Lightweight
Dependency Injection Framework
Dear Reader,
This book welcomes you to the world of Google Guice (pronounced “juice”), the latest and
greatest dependency injection framework that fully exploits all modern Java™ features. One
step at a time, this book will help turn any XML-spitting programmer into a true Guice master,
or a “Bob,” as I like to say.
I’m particularly proud of this book’s coverage. To make sure that nobody gets left behind, I
start out with an introduction to dependency injection concepts. From there, you will learn how
Guice makes your life easier, and you’ll gradually become a Guice expert. Beyond that, I also
devoted two chapters to web application development with Struts 2 and Wicket, including
content on how to organize your application and how to use Warp Persist, a popular Guice
extension, to access your data using the Java Persistence API and Hibernate.
Writing this book was not an easy task, so in addition to Apress, I’d like to thank some people
in particular. First, I would like to thank Dhanji R. Prasanna for referring me to Apress to write
this book. He has also done a fantastic job as my technical reviewer. I’d also like to thank Bob
Lee, the inventor of Guice, who kindly answered all of my questions and inspired much of the
content in Chapter 8. Finally, a big thank you goes out to my friends, my parents, my brother,
and anyone who believes in me; you are the people who put the smile on my face.
Now, put on your Batman or Catwoman costume; open up a bottle of wine; pick up this book;
and put your feet up. Be a Java hero, and may Guice help you on your way. Just don’t forget to
send me a picture of you in that getup.
Robbie Vanbrabant
http://garbagecollected.org
Google Guice: Agile Lightweight Dependency Injection Framework i
Contents
Chapter 1: Setting the Stage ......................................................................................... 1
The Problem................................................................................................................................... 1
A Fortunate Example .................................................................................................................... 3
Dependency Injection.................................................................................................................... 5
DI, Guice Style .............................................................................................................................. 8
Summary ...................................................................................................................................... 10
Chapter 2: Enter Guice .............................................................................................. 11
Getting Guice............................................................................................................................... 11
Preparing the Code ...................................................................................................................... 12
Specifying an Implementation.................................................................................................... 15
Bootstrapping............................................................................................................................... 15
Choosing Between Implementations.......................................................................................... 17
Implicit Bindings ......................................................................................................................... 21
Scoping......................................................................................................................................... 22
Debunking Myths ........................................................................................................................ 23
Summary ...................................................................................................................................... 27
Chapter 3: From Journeyman to Bob ......................................................................... 29
Providers ...................................................................................................................................... 29
@Named ...................................................................................................................................... 32
Binding Constants ....................................................................................................................... 34
Binding Generic Types ............................................................................................................... 38
Properties ..................................................................................................................................... 42
Static Injection ............................................................................................................................. 44
ii Google Guice: Agile Lightweight Dependency Injection Framework
Custom Scopes ............................................................................................................................ 45
Web Scopes.................................................................................................................................. 49
Organizing Modules .................................................................................................................... 51
The Binding EDSL ...................................................................................................................... 53
How Guice Resolves Dependencies........................................................................................... 56
Summary ...................................................................................................................................... 57
Chapter 4: Aspect-Oriented Programming ................................................................. 59
AOP for Mere Mortals ................................................................................................................ 60
How Guice AOP Works.............................................................................................................. 60
Method Interception .................................................................................................................... 61
Phoning Home ............................................................................................................................. 64
Summary ...................................................................................................................................... 69
Chapter 5: Integrating with the Web........................................................................... 71
The Integration Challenge........................................................................................................... 71
Bootstrapping............................................................................................................................... 72
Inviting Servlets to the Club ....................................................................................................... 73
Configuration Discovery............................................................................................................. 74
Struts 2 ......................................................................................................................................... 76
Wicket .......................................................................................................................................... 78
Where Are the Web Scopes? ...................................................................................................... 85
Warp Servlet ................................................................................................................................ 86
Summary ...................................................................................................................................... 92
Chapter 6: Practical Guice......................................................................................... 93
Requirements ............................................................................................................................... 93
The Big Picture ............................................................................................................................ 95
Project Structure .......................................................................................................................... 99
Setting Up Struts 2 .................................................................................................................... 103
Getting Guiced........................................................................................................................... 104
76a2626bcfb21763948a3d635f6fe985
Google Guice: Agile Lightweight Dependency Injection Framework iii
Defining the Model ................................................................................................................... 105
Database Access with Warp Persist ......................................................................................... 109
Implementing the Data Access Layer ......................................................................................111
The Home Screen ...................................................................................................................... 118
The Create and Edit Screens..................................................................................................... 121
Unit Testing ...............................................................................................................................123
Summary .................................................................................................................................... 125
Chapter 7: Guice Recipes ......................................................................................... 127
Sharing Singletons..................................................................................................................... 127
Binding Collections...................................................................................................................129
Designing Libraries and Limiting Visibility............................................................................ 136
Viral Annotations ...................................................................................................................... 138
Mixing Scopes ........................................................................................................................... 139
Integrating Spring...................................................................................................................... 142
Logging ...................................................................................................................................... 145
Integrating JNDI........................................................................................................................146
Using JMX................................................................................................................................. 147
Summary .................................................................................................................................... 150
Chapter 8: The Future.............................................................................................. 153
The Grand Plan .......................................................................................................................... 153
Growing an Extensible Platform .............................................................................................. 15 4
Better Up-Front Checking......................................................................................................... 155
Keeping Guice Simple and Making It Simpler ....................................................................... 156
Improved Tooling Support........................................................................................................ 158
Addressing DI Shortcomings....................................................................................................160
Standardization .......................................................................................................................... 164
Summary .................................................................................................................................... 166
剩余188页未读,继续阅读
资源评论
- leoncg2015-08-06内容有点老了,用的也有限,看看先。
- bmeson2014-01-23Google Guice是很好的新技术。
kittyjie
- 粉丝: 237
- 资源: 1615
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功