没有合适的资源?快使用搜索试试~ 我知道了~
首页Dependency Injection in Delphi.Nick Hodges.pdf
Dependency Injection in Delphi.Nick Hodges.pdf
需积分: 10 12 下载量 179 浏览量
更新于2023-05-17
评论
收藏 1.69MB PDF 举报
Dependency Injection in Delphi.Nick Hodges.pdf
资源详情
资源评论
资源推荐
Dependency Injection In Delphi
Nick Hodges
This book is for sale at http://leanpub.com/dependencyinjectionindelphi
This version was published on 2017-02-25
ISBN 978-1-941266-19-9
This is a Leanpub book. Leanpub empowers authors and publishers with the Lean
Publishing process. Lean Publishing is the act of publishing an in-progress ebook
using lightweight tools and many iterations to get reader feedback, pivot until you
have the right book and build traction once you do.
© 2015 - 2017 Nick Hodges
To my wonderful, beautiful wife Pamela. I love you.
Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i
Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . iii
What is Dependency Injection? . . . . . . . . . . . . . . . . . . . . . . . . 1
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
So What Exactly is Dependency Injection? . . . . . . . . . . . . . . . . . 3
What to Do? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Basic Principles to Follow . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Benefits of Dependency Injection . . . . . . . . . . . . . . . . . . . . . . . 10
A Closer Look at Coupling: Connascence . . . . . . . . . . . . . . . . . . . 12
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Connascence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Qualities of Connascence . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Levels of Connascence . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
What to Do About Connascence? . . . . . . . . . . . . . . . . . . . . . . 23
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Constructor Injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Constructor Injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Never Accept
nil
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
When to Use Constructor Injection . . . . . . . . . . . . . . . . . . . . . 28
Property Injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
CONTENTS
Method Injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
The Dependency Injection Container . . . . . . . . . . . . . . . . . . . . . 38
What is a Dependency Injection Container? . . . . . . . . . . . . . . . . 38
What is the Container? . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Why is a Container Needed? . . . . . . . . . . . . . . . . . . . . . . . . 40
Where to Use the Container . . . . . . . . . . . . . . . . . . . . . . . . . 40
When to Use the Container . . . . . . . . . . . . . . . . . . . . . . . . . 41
Capabilities and Functionality . . . . . . . . . . . . . . . . . . . . . . . 42
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
A Step-by-Step Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
The Beginning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Introducing Constructor Injection . . . . . . . . . . . . . . . . . . . . . 51
Coding to an Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Enter the Container . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Advanced Container Use . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Multiple Implementations at Runtime . . . . . . . . . . . . . . . . . . . 61
Lazy Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
Registering Factories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
Registering Primitive Parameters . . . . . . . . . . . . . . . . . . . . . . 73
Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Dependency Injection Anti-Patterns . . . . . . . . . . . . . . . . . . . . . 80
Service Locator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Field Injection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Constructor Over-Injection . . . . . . . . . . . . . . . . . . . . . . . . . 85
VCL Components in the Container . . . . . . . . . . . . . . . . . . . . . 88
Multiple Constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Mixing the Container in with Your Code . . . . . . . . . . . . . . . . . . 89
Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
A Simple, Useful, and Complete Example . . . . . . . . . . . . . . . . . . . 91
剩余117页未读,继续阅读
chunyangsuhao
- 粉丝: 99
- 资源: 7402
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- RTL8188FU-Linux-v5.7.4.2-36687.20200602.tar(20765).gz
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0