Dependency Injection in Delphi: use Spring4D and Nick Hodges’ book
Posted by jpluimers on 2018/12/06
Over the past few months, various people asked me where to get started with Dependency Injection in Delphi.
First of all, get this book:
[WayBack] Dependency Injection In… by Nick Hodges [Leanpub PDF/iPad/Kindle]
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.
It’s well worth reading.
Then buy this book and continue reading; it’s more extensive but coming from a Delphi background it’s better to read Nicks’ book first:
[WayBack] Dependency Injection in .NET: Mark Seemann: 9781935182504
Dependency Injection in .NET, winner of the 2013 Jolt Awards for Productivity, presents core DI patterns in plain C#, so you’ll fully understand how DI works, covers integration with standard Microsoft technologies like ASP.NET MVC, and teaches you to use DI frameworks like Structure Map, Castle Windsor, and Unity.
Then start at these demo projects:
- [WayBack] sglienke / Spring4D / source / Samples / IntroToDependencyInjection — Bitbucket
- [WayBack] sglienke / Spring4D / source / Samples / AdvancedDependencyInjection — Bitbucket
- [WayBack] sglienke / Spring4D / source / Samples / SOLP Demo — Bitbucket
Finally read through these posts and what they link to:
- [WayBack] Dependency Injection By Hand · ninject/Ninject Wiki
- [WayBack] A look at Dependency Injection and Inversion
Then compare what you learned with this:
- [WayBack] How not to do dependency injection – the static or singleton container
- [WayBack] Delphi sorcery: Dependency Injection best practices – lazy initialization
via: [Archive.is] Spring4D Dependency Injection: Get started – Google Groups
Thanks to [WayBack] David Schwartz – Google+ for the many insights at [WayBack] +Stefan Glienke, do you foresee any real issues one might encounter if he/she use the DI container linked below? The obvious issue would be that it does… – Edwin Yip – Google+. He has a great CodeRage video about it on YouTube too; see below.
Note I love Spring4D, so any links showing how to use it are worth reading.
A few more links there:
- Search for
.TestResolve;in Tests/Source/Core/Spring.Tests.Container.pas (via [WayBack] I’m using the Spring.Container in some refactoring and am looking for some clarification on the best way … factories – Russell Weetch – Google+) - [WayBack] Spring4d.Container – where to declare what? – Russell Weetch – Google+
–jeroen







Leave a comment