![brief contents Dependency Injection Principles Practices and Patterns Steven - photo 1](/uploads/posts/book/208936/image_fi/book_art/cover.png)
brief contents
Dependency Injection
Principles, Practices, and Patterns
Steven van Deursen
Mark Seemann
Manning
Shelter Island
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Email:
2019 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps.
Recognizing the importance of preserving what has been written, it is Mannings policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine.
Manning Publications Co.
20 Baldwin Road
PO Box 761
Shelter Island, NY 11964
Acquisitions editor:Mike Stephens
Development editors:Marina Michaels and Dan Maharry
Technical development editor:Karsten Strbk
Review editor:Ivan Martinovic
Production editor:Anthony Calcara
Copy editor:Frances Buran
Proofreader:Katie Tennant
Technical proofreader:Chris Heneghan
Typesetter:Happenstance Type-O-Rama
Cover designer:Marija Tudor
ISBN 9781617294730
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 SP 24 23 22 21 20 19
Praise for the First Edition
Realistic examples keep the big picture in focus A real treat.
Glenn Block Microsoft
Well-written, thoughtful, easy to follow, and timeless.
David Barkol Neudesic
Fills a huge need for .NET designers.
Paul Grebenc PCA Services
Takes the mystery out of a mystifying topic.
Rama Krishna 3C Software
A uniquely personal way to learn about modern software development principles in depth. Highly recommended!
Darren Neimke HomeStart Finance
All you ever need to know about dependency injection ... and more!
Jonas Bandi TechTalk
A must read on Dependency Injection.
Braj Panda Capgemini India
This book will be the definitive guide to Dependency Injection for the .NET stack.
Doug Ferguson Improving Enterprises
preface
Theres a peculiar phenomenon related to Microsoft called the Microsoft Echo Chamber. Microsoft is a huge organization, and the surrounding ecosystem of Microsoft Certified Partners multiplies that size by orders of magnitude. If youre sufficiently embedded in this ecosystem, it can be hard to see past its boundaries. Whenever you look for a solution to a problem with a Microsoft product or technology, youre likely to find an answer that involves throwing even more Microsoft products at it. No matter what you yell within the echo chamber, the answer is Microsoft!
When Microsoft hired me (Mark) in 2003, I was already firmly embedded in the echo chamber, having worked for Microsoft Certified Partners for yearsand I loved it! They soon shipped me off to an internal tech conference in New Orleans to learn about the latest and greatest Microsoft technology.
Today, I cant recall any of the Microsoft product sessions I attendedbut I do remember the last day. On that day, having failed to experience any sessions that could satisfy my hunger for cool tech, I was mostly looking forward to flying home to Denmark. My top priority was to find a place to sit so I could attend to my email, so I chose a session that seemed marginally relevant for me and fired up my laptop.
The session was loosely structured and featured several presenters. One was a bearded guy named Martin Fowler, who talked about Test-Driven Development (TDD) and dynamic mocks. I had never heard of him, and I didnt listen very closely, but something must have stuck in my mind.
Soon after returning to Denmark, I was tasked with rewriting a big ETL (extract, transform, load) system from scratch, and I decided to give TDD a try (it turned out to be a very good decision). The use of dynamic mocks followed naturally, but also introduced the need to manage dependencies. I found that to be a very difficult but very captivating problem, and I couldnt stop thinking about it.
What started as a side effect of my interest in TDD became a passion in itself. I did a lot of research, read lots of blog posts about the matter, wrote quite a few blogs myself, experimented with code, and discussed the topic with anyone who cared to listen. Increasingly, I had to look outside the Microsoft Echo Chamber for inspiration and guidance. Along the way, people associated me with the ALT.NET movement even though I was never very active in it. I made all the mistakes it was possible to make, but I was gradually able to develop a coherent understanding of Dependency Injection (DI).
When Manning approached me with the idea for a book about Dependency Injection in .NET, my first reaction was, Is this even necessary? I felt that all the concepts a developer needs to understand DI were already described in numerous blog posts. Was there anything to add? Honestly, I thought DI in .NET was a topic that had been done to death already.
Upon reflection, however, it dawned on me that while the knowledge is definitely out there, its very scattered and uses a lot of conflicting terminology. Before the first edition of this book, there were no titles about DI that attempted to present a coherent description of it. After thinking about it further, I realized that Manning was offering me a tremendous challenge and a great opportunity to collect and systematize all that I knew about DI.
The result is this book and its predecessorthe first edition. It uses .NET Core and C# to introduce and describe a comprehensive terminology and guidance for DI, but I hope the value of this book will reach well beyond the platform. I think the pattern language articulated here is universal. Whether youre a .NET developer or use another object-oriented platform, I hope this book will help you be a better software engineer.
acknowledgments
Gratitude may seem like a clich, but this is only because its such a fundamental part of human nature. While we were writing the book, many people gave us good reasons to be grateful, and we would like to thank them all.
First of all, writing a book in our spare time has given us a new understanding of just how taxing such a project is on marriage and family life. Marks wife Cecilie stayed with him and actively supported him during the whole process. Most significantly, she understood just how important this project was to him. Theyre still together, and Mark looks forward to being able to spend more time with her and their kids Linea and Jarl. Stevens wife Judith gave him the space needed to complete this immense undertaking, but she certainly is glad that the project is
Next page