舉報

會員
Hands-On Dependency Injection in Go
Hands-OnDependencyInjectioninGotakesyouonajourney,teachingyouaboutrefactoringexistingcodetoadoptdependencyinjection(DI)usingvariousmethodsavailableinGo.Ofthesixmethodsintroducedinthisbook,someareconventional,suchasconstructorormethodinjection,andsomeunconventional,suchasjust-in-timeorconfiginjection.Eachmethodisexplainedindetail,focusingontheirstrengthsandweaknesses,andisfollowedwithastep-by-stepexampleofhowtoapplyit.Withplentyofexamples,youwilllearnhowtoleverageDItotransformcodeintosomethingsimpleandflexible.Youwillalsodiscoverhowtogenerateandleveragethedependencygraphtospotandeliminateissues.Throughoutthebook,youwilllearntoleverageDIincombinationwithteststubsandmockstotestotherwisetrickyorimpossiblescenarios.Hands-OnDependencyInjectioninGotakesapragmaticapproachandfocusesheavilyonthecode,userexperience,andhowtoachievelong-termbenefitsthroughincrementalchanges.Bytheendofthisbook,youwillhaveproducedcleancodethat’seasytotest.
目錄(236章)
倒序
- coverpage
- Title Page
- Dedication
- About Packt
- Why subscribe?
- Packt.com
- Contributors
- About the author
- About the reviewer
- Packt is searching for authors like you
- Preface
- Who this book is for
- What this book covers
- To get the most out of this book
- Download the example code files
- Download the color images
- Conventions used
- Get in touch
- Reviews
- Never Stop Aiming for Better
- Technical requirements
- Why does DI matter?
- So how do I define DI?
- Code smells that indicate you might need DI
- Code bloat
- Resistance to change
- Wasted effort
- Tight coupling
- Healthy skepticism
- A quick word about idiomatic Go
- Leave your baggage at the door
- Summary
- Questions
- Further reading
- SOLID Design Principles for Go
- Technical requirements
- Single responsibility principle (SRP)
- How does this relate to DI?
- What does this mean for Go?
- Go interfaces structs and functions
- Go packages
- Open/closed principle (OCP)
- How does this relate to DI?
- What does this mean for Go?
- Liskov substitution principle (LSP)
- How does this relate to DI?
- What does this mean for Go?
- Interface segregation principle (ISP)
- How does this relate to DI?
- What does this mean for Go?
- Dependency inversion principle (DIP)
- How does this relate to DI?
- What does this mean for Go?
- Summary
- Questions
- Further reading
- Coding for User Experience
- Technical requirements
- Optimizing for humans
- What does user experience mean for Go code?
- Start with simple – get complicated only when you must
- Apply just enough abstraction
- Follow industry team and language conventions
- Export only what you must
- Aggressively apply the single responsibility principle
- Discovering a good user experience
- Who is the user?
- What are your users capable of?
- Why do users want to use your code?
- How do they expect to use it?
- When to compromise
- Final thoughts on coding for user experience
- A security blanket named unit tests
- So why do I write unit tests?
- What should I test?
- Table-driven tests
- Stubs
- Mocks
- Test-induced damage
- Warning signs of test-induced damage
- Parameters config options or outputs that only exist because of tests
- Parameters that cause or are caused by leaky abstractions
- Publishing mocks in production code
- Excessive test coverage
- Visualizing your package dependencies with Godepgraph
- Installing the tools
- Generating a dependency graph
- Interpreting the dependency graph
- Summary
- Questions
- Introduction to the ACME Registration Service
- Technical requirements
- Goals for our system
- High readability
- High testability
- Low coupling
- Final thoughts on goals
- Introduction to our system
- Software architecture
- Known issues
- Testability
- Duplication of effort
- Lack of isolation in tests
- High coupling between the data and REST packages
- High coupling with the config package
- Downstream currency service
- Summary
- Questions
- Dependency Injection with Monkey Patching
- Technical requirements
- Monkey magic!
- Advantages of monkey patching
- Applying monkey patching
- Introducing SQLMock
- Monkey patching with SQLMock
- Testing error handling
- Reducing test bloat with table-driven tests
- Monkey patching between packages
- When the magic fades
- Summary
- Questions
- Further reading
- Dependency Injection with Constructor Injection
- Technical requirements
- Constructor injection
- Addressing the duck in the room
- Advantages of constructor injection
- Applying constructor injection
- Decoupling from the dependency
- Building the constructor
- Improving test scenario coverage
- Validating our improvements with the dependency graph
- Disadvantages of constructor injection
- Summary
- Questions
- Dependency Injection with Method Injection
- Technical requirements
- Method injection
- Advantages of method injection
- Applying method injection
- A quick recap
- Stopping short
- Applying method injection to the data package
- Applying method injection to the exchange package
- Applying method injection to the model layer (the Get List and Register packages)
- Applying the method injection of context to the REST package
- Latency budgets
- Disadvantages of method injection
- Summary
- Questions
- Dependency Injection by Config
- Technical requirements
- Config injection
- Advantages of config injection
- Applying config injection
- Applying config injection to the model layer
- Applying config injection to the data package
- Applying config injection to the exchange package
- Boundary tests
- Disadvantages of config injection
- Summary
- Questions
- Just-in-Time Dependency Injection
- Technical requirements
- JIT injection
- Advantages of JIT injection
- Applying JIT injection
- Private dependencies
- Unit test coverage
- Coverage and dependency graph
- Chasing away the monkeys
- Optional public dependencies
- Disadvantages of JIT injection
- Summary
- Questions
- Off-the-Shelf Injection
- Technical requirements
- Off-the-shelf injection with Wire
- Introducing providers
- Understanding injectors
- Adopting provider sets
- Advantages of off-the-shelf injection
- Applying off-the-shelf injection
- Adopting Google Wire
- API regression tests
- Disadvantages of off-the-shelf injection
- Summary
- Questions
- Curb Your Enthusiasm
- Technical requirements
- DI induced damage
- A long constructor parameter list
- Injecting an object when config would do
- Needless indirection
- Service locator
- Premature future-proofing
- Mocking HTTP requests
- Mocking an HTTP request with DI
- Mocking HTTP requests with config
- Unnecessary injection
- Summary
- Questions
- Reviewing Our Progress
- Technical requirements
- Overview of the improvements
- Global singletons
- High coupling with the config package
- Removing the dependence on upstream service
- Stopping short and latency budgets
- Simplified dependency creation
- Coupling and extensibility
- Review of the dependency graph
- Review of test coverage and testability
- Test coverage
- Starting a new service with DI
- The user experience
- Code structure
- Cross-cutting concerns
- Designing from outside-in
- Summary
- Questions
- Assessment
- Chapter 1 Never Stop Aiming for Better
- Chapter 2 SOLID Design Principles for Go
- Chapter 3 Coding for User Experience
- Chapter 4 Introduction to the ACME Registration Service
- Chapter 5 Dependency Injection with Monkey Patching
- Chapter 6 Dependency Injection with Constructor Injection
- Chapter 7 Dependency Injection with Method Injection
- Chapter 8 Dependency Injection by Config
- Chapter 9 Just-in-Time Dependency Injection
- Chapter 10 Off-the-Shelf Injection
- Chapter 11 Curbing Your Enthusiasm
- Chapter 12 Reviewing Our Progress
- Other Books You May Enjoy
- Leave a review - let other readers know what you think 更新時間:2021-06-10 19:18:21
推薦閱讀
- AngularJS入門與進階
- Getting Started with Gulp(Second Edition)
- 零基礎搭建量化投資系統:以Python為工具
- Docker and Kubernetes for Java Developers
- Docker技術入門與實戰(第3版)
- Building a Game with Unity and Blender
- SpringMVC+MyBatis快速開發與項目實戰
- Unity 2020 Mobile Game Development
- Instant 960 Grid System
- VSTO開發入門教程
- Visual Basic程序設計習題解答與上機指導
- 小程序開發原理與實戰
- Cocos2d-x學習筆記:完全掌握Lua API與游戲項目開發 (未來書庫)
- PHP 7從零基礎到項目實戰
- Python函數式編程(第2版)
- 川哥教你Spring Boot 2實戰
- TypeScript High Performance
- PHP面試一戰到底
- Node.js入門指南
- Android性能優化之道:從底層原理到一線實踐
- 基于Kubernetes的容器云平臺實戰
- Ionic:Hybrid Mobile App Development
- Docker與Kubernetes容器虛擬化技術與應用
- Flutter基礎與實戰:從入門到APP跨平臺開發
- Blueprints Visual Scripting for Unreal Engine
- Unreal Engine 4.x Scripting with C++ Cookbook
- UML軟件建模技術
- Mastering Windows Server 2016
- Python編程從小白到大牛
- Mastering Microservices with Java 9(Second Edition)