Dependency Injection in Delphi Paperback – April 18, 2017
|New from||Used from|
Enter your mobile number or email address below and we'll send you a link to download the free Kindle App. Then you can start reading Kindle books on your smartphone, tablet, or computer - no Kindle device required.
To get the free app, enter your mobile phone number.
Frequently bought together
Customers who viewed this item also viewed
- Item Weight : 11 ounces
- Paperback : 132 pages
- ISBN-13 : 978-1941266229
- Publisher : Nepeta Enterprises (April 18, 2017)
- Product dimensions : 7.5 x 0.3 x 9.25 inches
- Language: : English
- Customer Reviews:
Top reviews from the United States
There was a problem filtering reviews right now. Please try again later.
But as a book it lacks a number of qualities that would have been useful. On the mundane level, there's no index, and no chapter numbers. More significantly, there seems to have been minimal vetting as to whether the intended readers would find the material presented in a sequence that answers the questions that would arise along the way.
For example, in the Dependency Injection Container chapter, the first section is "What is a Dependency Injection Container?" which completely avoids telling us what it is, instead focusing on what it is not -- none of which will make sense to a reader who doesn't already have some idea of what a DI container is. Guess what the next section is? "What is the Container?". I think it's very helpful to discuss what a thing is not, to dispel misunderstandings, but only after the reader has a good grasp of what it IS and has been introduced to the vocabulary in which the "what it's not" discussion will be phrased.
This entire chapter ends with "That's the basics of the Container." Except it isn't -- all that's been covered is how to register interfaces and classes into the container. No concrete discussion, nor code, explaining what on earth the container does for us, except for a brief mention that at the beginning of our code we're supposed to call the Container to "resolve" the entire object graph for the application, whatever that means.
This does all become clearer in subsequent chapters, except that it leaves open the gnawing question -- "wait, surely applications (especially GUI apps) need to construct (and destroy) additional branches of objects later than just at the beginning?" (setting aside the actual VCL or FMX classes that have their own management). Yet there is much advocacy (and simple examples) of doing it only at the beginning. Maybe I missed something, but I don't see how to extrapolate those examples to real applications.
But there might be hope in the GUI FileViewer example which ends the book. Here the code shows that the DI Container is created in the FormCreate, and not at the beginning of the application. Ah-HAH! Maybe this is where we learn that actually multiple separate DI Containers can and should be used more locally, so that the lifetimes of the objects they manage can parallel whatever else is going on the app -- here the lifetime of a form (albeit that in this demo there is only one form, so that lifecycle is almost the same as the app.).
But here we run aground because the code fails to even show where the DI Container is populated! And there is no commentary on this striking deviation from the book's categorical statements like "you should use the Container once and only once at the composite (composition?) root of your application... I assure you it can be done".
Suspecting a bug in the code, perhaps we can go look into the downloadable sample code. There we find (after considerable hassle getting Atlassian's SourceTree to work, no fault of this book, of course) at least three separate copies of the code (in multiple versions, in a version-control sense). There is one that does complete the book's code, and at least confirmed my suspicion of what was missing. There are two other versions that use the DI Container in ways that the book says are not correct. (The author does mention he's changed his views on a couple of principles -- it would be helpful if the repo had a conspicuous README_DelphiDependencyInjection file pointing to the correctest code.)
Bottom line: I am glad this book exists for Delphi, especially given that no doubt the sales for this kind of title do not lead quickly to retirement in luxury. It appears that much of the advice parallels what one might find in other DI or Spring books, but it's nice that the book confirms that it can be done in Delphi, with Spring4D. I just wish there had been the time to take a bit more care with having it all make sense with a bit less struggle.
For example, these techniques make test driven development much easier by first writing an interface with mock code and then substituting real code behind the same interface.
Unless you're already using these techniques, this book will (or at least should) change the way you code and provide patterns to assist you.
The one thing it doesn't do is rewrite your old code. :-)
The code as printed in the book, does NOT match the code download from the link as referenced in the book. For example, the FileViewer example, the code downloaded from the link still uses GlobalContainer, while the code in the book uses local container. This is kind of some headache for readers. But it doesn't impact understanding anyway.
Hope the author can update the sample code to be consistent with the book soon.