{"id":258392,"date":"2026-07-13T16:14:46","date_gmt":"2026-07-13T13:14:46","guid":{"rendered":"https:\/\/1kitap1.com\/en\/dependency-injection-principles-practices-and-patterns-mark-seemann\/"},"modified":"2026-07-13T16:14:46","modified_gmt":"2026-07-13T13:14:46","slug":"dependency-injection-principles-practices-and-patterns-mark-seemann","status":"publish","type":"post","link":"https:\/\/1kitap1.com\/en\/dependency-injection-principles-practices-and-patterns-mark-seemann\/","title":{"rendered":"Dependency Injection Principles Practices And Patterns &#8211; Mark Seemann"},"content":{"rendered":"<figure style=\"text-align:center;margin:0 auto 1.5em;\"><img decoding=\"async\" src=\"https:\/\/1kitap1.com\/en\/wp-content\/uploads\/2026\/07\/c1f2881a62d1acd1.jpg\" alt=\" - Unknown book cover\" style=\"max-width:300px;width:100%;height:auto;box-shadow:0 4px 12px rgba(0,0,0,.25);border-radius:4px;\"\/><\/figure>\n<p>This is the method where you get the chance to wire up all required Dependencies and supply them to the controller before returning the instance. You\u2019ll see an example in a moment. If you created any resources that need to be explicitly disposed of, you can do that when the Release method is called.<\/p>\n<p>We\u2019ll go into further details about releasing components in the next chapter. A more practical way to ensure that Dependencies are disposed of is to add them to the list of disposable request objects using the HttpContext.Response.RegisterForDispose method. Although implementing a custom controller activator is the hard part, it won\u2019t be used unless we tell ASP.NET Core MVC about it. Using a custom controller activator in ASP.NET Core A custom controller activator can be added as part of the application startup sequence \u2014 usually in the Startup class.<\/p>\n<p>They\u2019re used by calling AddSingleton<IControllerActivator> on the IServiceCollection instance. The next listing shows the Startup class from the sample e-commerce application. Listing 7.7 Commerce application\u2019s Startup class public class Startup { public Startup(IConfiguration configuration) { this.Configuration = configuration; } public IConfiguration Configuration { get; } public void ConfigureServices(IServiceCollection services) { services.AddMvc(); var controllerActivator = new CommerceControllerActivator( Configuration.GetConnectionString(&#8220;CommerceConnectionString&#8221;)); services.AddSingleton<IControllerActivator> (controllerActivator); } public void Configure(ApplicationBuilder app, IHostingEnvironment env) { &#8230; } } This listing creates a new instance of the custom CommerceControllerActivator.<\/p>\n<p>By adding it to the list of known services using AddSingleton, you ensure the creation of controllers is Intercepted by your custom controller activator. If this code looks vaguely familiar, it\u2019s because you saw something similar in section 4.1.3. Back then, we promised to show you how to implement a custom controller activator in chapter 7, and what do you know?<\/p>\n<p>This is chapter 7. Example: implementing the CommerceControllerActivator As you might recall from chapters 2 and 3, the e-commerce sample application presents the visitor of the website with a list of products and their prices. In section 6.2, we added a feature that allowed users to calculate a route between two locations. Although we\u2019ve shown several snippets of the Composition Root, we didn\u2019t show a complete example.<\/p>\n<blockquote>\n<p>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: orders@manning.com \u00a92019 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.<\/p>\n<p>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 Manning\u2019s 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.<\/p>\n<p>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 Str\u00f8b\u00e6k Review editor: Ivan Martinovic\u00b4 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 \u2013 SP \u2013 24 23 22 21 20 19 OceanofPDF.com brief contents Part 1: Putting Dependency Injection on the map Chapter 1: First steps Chapter 2: Building blocks Chapter 3: Control flow Part 2: Catalog Chapter 4: Data abstractions Chapter 5: Concurrency primitives Chapter 6: Generic server processes Part 3: Pure DI Chapter 7: Building a concurrent system Chapter 8: Fault-tolerance basics Chapter 9: Isolating error effects Chapter 10: Beyond GenServer Part 4: DI Containers Chapter 11: Working with components Chapter 12: Building a distributed system Chapter 13: Running the system OceanofPDF.com contents Cover Titlepage Copyright Brief Contents Contents praise for the first edition preface acknowledgments about this book Who should read this book?<\/p>\n<\/blockquote>\n<p><em>This is a short excerpt from the opening of &ldquo;&rdquo; by Unknown, quoted for review and introduction purposes. All rights belong to the copyright holders.<\/em><\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/1kitap1.com\/en\/dependency-injection-principles-practices-and-patterns-mark-seemann\/#Book_Information\" >Book Information<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/1kitap1.com\/en\/dependency-injection-principles-practices-and-patterns-mark-seemann\/#Reading_Word_Statistics\" >Reading &amp; Word Statistics<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/1kitap1.com\/en\/dependency-injection-principles-practices-and-patterns-mark-seemann\/#Most_Frequent_Words\" >Most Frequent Words<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/1kitap1.com\/en\/dependency-injection-principles-practices-and-patterns-mark-seemann\/#PDF_Download\" >PDF Download<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Book_Information\"><\/span>Book Information<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><strong>Unique ID:<\/strong> c1f2881a62d1acd1<\/li>\n<li><strong>File Extension:<\/strong> .pdf<\/li>\n<li><strong>File Size:<\/strong> 17,809,433 bytes (16.984 MB)<\/li>\n<li><strong>Title:<\/strong> &#8211;<\/li>\n<li><strong>Author:<\/strong> Unknown<\/li>\n<li><strong>ISBN:<\/strong> 9781617294730<\/li>\n<li><strong>Pages:<\/strong> 918<\/li>\n<li><strong>Language:<\/strong> English (en)<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Reading_Word_Statistics\"><\/span>Reading &amp; Word Statistics<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li><strong>Estimated Reading Time:<\/strong> 867.1 minutes<\/li>\n<li><strong>Total Words:<\/strong> 173,419<\/li>\n<li><strong>Total Characters:<\/strong> 1,195,846<\/li>\n<li><strong>Average Words per Page:<\/strong> 188.91<\/li>\n<li><strong>Average Characters per Page:<\/strong> 1302.66<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Most_Frequent_Words\"><\/span>Most Frequent Words<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>listing (808), code (748), class (736), application (733), method (714), new (706), dependency (696), use (667), dependencies (647), container (640), using (574), public (541), type (526), constructor (498), instance (487), object (464), figure (444), example (437), it\u2019s (436), section (431), chapter (430), configuration (405), composition (385), interface (384), injection (382), implementation (372), one (350), root (349), service (347), we\u2019ll (328), design (324), simple (321), abstraction (316), classes (292), components (287), need (286), net (266), single (264), also (261), register (255), context (252), data (246), time (245), types (245), create (238), many (234), layer (233), part (230), lifetime (229), get (228), instances (226), see (226), pattern (224), instead (222), even (221), case (220), shows (219), implementations (216), services (213), scope (212), like (212), productservice (211), injector (210), domain (207), following (207), although (207), access (198), repository (197), iingredient (195), containers (191), patterns (190), decorator (190), different (190), var (190), way (189), now (188), core (187), resolve (186), graph (185), principle (185), property (179), product (179), system (178), autofac (178), multiple (177), want (177), private (177), isn\u2019t (176), make (174), used (173), lifestyle (173), iproductrepository (172), first (171), assembly (171), abstractions (169), common (169), concrete (169), next (169), however (168), don\u2019t (168).<\/p>\n<h2><span class=\"ez-toc-section\" id=\"PDF_Download\"><\/span>PDF Download<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p style=\"text-align:center;\"><a href=\"https:\/\/1kitap1.com\/en\/wp-content\/uploads\/2026\/07\/dependency-injection-principles-practices-and-patterns-mark-seemann.pdf\" download rel=\"nofollow\" style=\"display:inline-block;background:#2271b1;color:#ffffff;padding:14px 36px;border-radius:6px;text-decoration:none;font-weight:bold;font-size:1.05em;\">&#11015;&#65039; PDF Download<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the method where you get the chance to wire up all required Dependencies and supply them to the controller before returning the instance. You\u2019ll see an example in a moment. If you created any resources that need to be explicitly disposed of, you can do that when the Release method is called. We\u2019ll [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":258390,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-258392","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-english"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/posts\/258392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/comments?post=258392"}],"version-history":[{"count":0,"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/posts\/258392\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/media\/258390"}],"wp:attachment":[{"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/media?parent=258392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/categories?post=258392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1kitap1.com\/en\/wp-json\/wp\/v2\/tags?post=258392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}