Dependency Injection In Delphi
Book information
Description
This book covers Dependency Injection from A to Z. In it you'll learn about Constructor Injection, Property Injection, and Method Injection. You'll learn about the right and wrong way to use the Dependency Injection Container 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 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 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 Interfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91 The File Displayer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Building Displayers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96 Tying It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 Connecting to the User Interface . . . . . . . . . . . . . . . . . . . . . . 103 Ways to Improve This Application . . . . . . . . . . . . . . . . . . . . . 106 Conclusions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 Final Thoughts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Similar books
Programming in PASCAL
1980 · PDF
Delphi Masterworks of Frédéric Chopin (Illustrated)
EPUB
Hands-On Design Patterns with Delphi
2019 · EPUB
More Coding in Delphi
2015 · PDF
More Coding in Delphi
2015 · PDF
Coding In Delphi
2013 · PDF
Kylix 2 Development
2002 · PDF
MySQL® Notes for Professionals book
2018 · PDF