没有合适的资源?快使用搜索试试~ 我知道了~
首页Dependency Injection in Delphi.Nick Hodges.pdf
Dependency Injection in Delphi.Nick Hodges.pdf
需积分: 10 152 浏览量
更新于2023-05-29
评论
收藏 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
- 粉丝: 97
- 资源: 7417
上传资源 快速赚钱
我的内容管理 收起
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助

会员权益专享
最新资源
- Xilinx SRIO详解.pptx
- Informatica PowerCenter 10.2 for Centos7.6安装配置说明.pdf
- 现代无线系统射频电路实用设计卷II 英文版.pdf
- 电子产品可靠性设计 自己讲课用的PPT,包括设计方案的可靠性选择,元器件的选择与使用,降额设计,热设计,余度设计,参数优化设计 和 失效分析等
- MPC5744P-DEV-KIT-REVE-QSG.pdf
- 通信原理课程设计报告(ASK FSK PSK Matlab仿真--数字调制技术的仿真实现及性能研究)
- ORIGIN7.0使用说明
- 在VMware Player 3.1.3下安装Redhat Linux详尽步骤
- python学生信息管理系统实现代码
- 西门子MES手册 13 OpcenterEXCR_PortalStudio1_81RB1.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

评论0