Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Dependency Injection in Go

You're reading from   Hands-On Dependency Injection in Go Develop clean Go code that is easier to read, maintain, and test

Arrow left icon
Product type Paperback
Published in Nov 2018
Publisher Packt
ISBN-13 9781789132762
Length 346 pages
Edition 1st Edition
Languages
Arrow right icon
Author (1):
Arrow left icon
Corey Scott Corey Scott
Author Profile Icon Corey Scott
Corey Scott
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Never Stop Aiming for Better 2. SOLID Design Principles for Go FREE CHAPTER 3. Coding for User Experience 4. Introduction to the ACME Registration Service 5. Dependency Injection with Monkey Patching 6. Dependency Injection with Constructor Injection 7. Dependency Injection with Method Injection 8. Dependency Injection by Config 9. Just-in-Time Dependency Injection 10. Off-the-Shelf Injection 11. Curb Your Enthusiasm 12. Reviewing Our Progress 13. Assessment 14. Other Books You May Enjoy

What this book covers

Chapter 1, Never Stop Aiming for Better, aims to define dependency injection, outline why dependency injection is important for Go development, and introduce several code smells that may be addressed with dependency injection.

Chapter 2, SOLID Design Principles for Go, introduces the SOLID software design principles and how they relate to both dependency injection and programming in Go.

Chapter 3, Coding for User Experience, addresses often overlooked concepts in programming, namely testing and the code's user experience. It also introduces many other concepts, including mocks, stubs, test-induced damage and the dependency graph, that we will use throughout the book.

Chapter 4, Introduction to the ACME Registration Service, introduces a small, fake service that forms the basis for many of our examples in later chapters. It highlights the issues with the service's current implementation and outlines the goals we are hoping to achieve by applying dependency injection.

Chapter 5, Dependency Injection with Monkey Patching, examines monkey patching as a way to swap out dependencies during our tests. This chapter applies monkey patching to our sample service to decouple our tests from the database, and to decouple the different layers from each other, all without resorting to significant refactoring.

Chapter 6Dependency Injection with Constructor Injection, introduces perhaps the most traditional form of dependency injection – constructor injection. This chapter will examine its many advantages, its disadvantages, and show how to successfully apply constructor injection.

Chapter 7Dependency Injection with Method Injection, introduces the second most common form of dependency injection – method injection. This chapter discusses the advantages and disadvantages of method injection and shows how to successfully apply the method for request-scoped dependencies.

Chapter 8Dependency Injection by Config, introduces config injection. Config injection is an extension of constructor and method injection that intends to improve the usability of the code by reducing the number of parameters.

 Chapter 9, Just-in-Time Dependency Injection, discusses another unusual form of dependency injection – just-in-time injection. Just-in-time (JIT) injection is a strategy that gives us many of the benefits of dependency injection, such as decoupling and testability, without adding parameters to our constructors or methods.

Chapter 10, Off-the-Shelf Injection, introduces the final dependency injection method – dependency injection using a framework. This chapter outlines the advantages and disadvantages related to adopting a dependency injection framework and also introduces and applies Google Go Cloud's wire framework to our sample service.

Chapter 11, Curb Your Enthusiasm, examines some of the ways in which dependency injection can go wrong. It offers many examples where applying dependency injection is either unnecessary or detrimental to the code.

Chapter 12, Reviewing Our Progress, contrasts the state of our sample service after applying dependency injection with the state it was in when it was introduced. It also discusses the steps we could have taken if we were starting a new service with dependency injection.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image