舉報(bào)

會員
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.
最新章節(jié)
- Leave a review - let other readers know what you think
- Other Books You May Enjoy
- Chapter 12 Reviewing Our Progress
- Chapter 11 Curbing Your Enthusiasm
- Chapter 10 Off-the-Shelf Injection
- Chapter 9 Just-in-Time Dependency Injection
品牌:中圖公司
上架時(shí)間:2021-06-10 18:24:48
出版社:Packt Publishing
本書數(shù)字版權(quán)由中圖公司提供,并由其授權(quán)上海閱文信息技術(shù)有限公司制作發(fā)行
- Leave a review - let other readers know what you think 更新時(shí)間:2021-06-10 19:18:21
- Other Books You May Enjoy
- Chapter 12 Reviewing Our Progress
- Chapter 11 Curbing Your Enthusiasm
- Chapter 10 Off-the-Shelf Injection
- Chapter 9 Just-in-Time Dependency Injection
- Chapter 8 Dependency Injection by Config
- Chapter 7 Dependency Injection with Method Injection
- Chapter 6 Dependency Injection with Constructor Injection
- Chapter 5 Dependency Injection with Monkey Patching
- Chapter 4 Introduction to the ACME Registration Service
- Chapter 3 Coding for User Experience
- Chapter 2 SOLID Design Principles for Go
- Chapter 1 Never Stop Aiming for Better
- Assessment
- Questions
- Summary
- Designing from outside-in
- Cross-cutting concerns
- Code structure
- The user experience
- Starting a new service with DI
- Test coverage
- Review of test coverage and testability
- Review of the dependency graph
- Coupling and extensibility
- Simplified dependency creation
- Stopping short and latency budgets
- Removing the dependence on upstream service
- High coupling with the config package
- Global singletons
- Overview of the improvements
- Technical requirements
- Reviewing Our Progress
- Questions
- Summary
- Unnecessary injection
- Mocking HTTP requests with config
- Mocking an HTTP request with DI
- Mocking HTTP requests
- Premature future-proofing
- Service locator
- Needless indirection
- Injecting an object when config would do
- A long constructor parameter list
- DI induced damage
- Technical requirements
- Curb Your Enthusiasm
- Questions
- Summary
- Disadvantages of off-the-shelf injection
- API regression tests
- Adopting Google Wire
- Applying off-the-shelf injection
- Advantages of off-the-shelf injection
- Adopting provider sets
- Understanding injectors
- Introducing providers
- Off-the-shelf injection with Wire
- Technical requirements
- Off-the-Shelf Injection
- Questions
- Summary
- Disadvantages of JIT injection
- Optional public dependencies
- Chasing away the monkeys
- Coverage and dependency graph
- Unit test coverage
- Private dependencies
- Applying JIT injection
- Advantages of JIT injection
- JIT injection
- Technical requirements
- Just-in-Time Dependency Injection
- Questions
- Summary
- Disadvantages of config injection
- Boundary tests
- Applying config injection to the exchange package
- Applying config injection to the data package
- Applying config injection to the model layer
- Applying config injection
- Advantages of config injection
- Config injection
- Technical requirements
- Dependency Injection by Config
- Questions
- Summary
- Disadvantages of method injection
- Latency budgets
- Applying the method injection of context to the REST package
- Applying method injection to the model layer (the Get List and Register packages)
- Applying method injection to the exchange package
- Applying method injection to the data package
- Stopping short
- A quick recap
- Applying method injection
- Advantages of method injection
- Method injection
- Technical requirements
- Dependency Injection with Method Injection
- Questions
- Summary
- Disadvantages of constructor injection
- Validating our improvements with the dependency graph
- Improving test scenario coverage
- Building the constructor
- Decoupling from the dependency
- Applying constructor injection
- Advantages of constructor injection
- Addressing the duck in the room
- Constructor injection
- Technical requirements
- Dependency Injection with Constructor Injection
- Further reading
- Questions
- Summary
- When the magic fades
- Monkey patching between packages
- Reducing test bloat with table-driven tests
- Testing error handling
- Monkey patching with SQLMock
- Introducing SQLMock
- Applying monkey patching
- Advantages of monkey patching
- Monkey magic!
- Technical requirements
- Dependency Injection with Monkey Patching
- Questions
- Summary
- Downstream currency service
- High coupling with the config package
- High coupling between the data and REST packages
- Lack of isolation in tests
- Duplication of effort
- Testability
- Known issues
- Software architecture
- Introduction to our system
- Final thoughts on goals
- Low coupling
- High testability
- High readability
- Goals for our system
- Technical requirements
- Introduction to the ACME Registration Service
- Questions
- Summary
- Interpreting the dependency graph
- Generating a dependency graph
- Installing the tools
- Visualizing your package dependencies with Godepgraph
- Excessive test coverage
- Publishing mocks in production code
- Parameters that cause or are caused by leaky abstractions
- Parameters config options or outputs that only exist because of tests
- Warning signs of test-induced damage
- Test-induced damage
- Mocks
- Stubs
- Table-driven tests
- What should I test?
- So why do I write unit tests?
- A security blanket named unit tests
- Final thoughts on coding for user experience
- When to compromise
- How do they expect to use it?
- Why do users want to use your code?
- What are your users capable of?
- Who is the user?
- Discovering a good user experience
- Aggressively apply the single responsibility principle
- Export only what you must
- Follow industry team and language conventions
- Apply just enough abstraction
- Start with simple – get complicated only when you must
- What does user experience mean for Go code?
- Optimizing for humans
- Technical requirements
- Coding for User Experience
- Further reading
- Questions
- Summary
- What does this mean for Go?
- How does this relate to DI?
- Dependency inversion principle (DIP)
- What does this mean for Go?
- How does this relate to DI?
- Interface segregation principle (ISP)
- What does this mean for Go?
- How does this relate to DI?
- Liskov substitution principle (LSP)
- What does this mean for Go?
- How does this relate to DI?
- Open/closed principle (OCP)
- Go packages
- Go interfaces structs and functions
- What does this mean for Go?
- How does this relate to DI?
- Single responsibility principle (SRP)
- Technical requirements
- SOLID Design Principles for Go
- Further reading
- Questions
- Summary
- Leave your baggage at the door
- A quick word about idiomatic Go
- Healthy skepticism
- Tight coupling
- Wasted effort
- Resistance to change
- Code bloat
- Code smells that indicate you might need DI
- So how do I define DI?
- Why does DI matter?
- Technical requirements
- Never Stop Aiming for Better
- Reviews
- Get in touch
- Conventions used
- Download the color images
- Download the example code files
- To get the most out of this book
- What this book covers
- Who this book is for
- Preface
- Packt is searching for authors like you
- About the reviewer
- About the author
- Contributors
- Packt.com
- Why subscribe?
- About Packt
- Dedication
- Title Page
- coverpage
- 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 更新時(shí)間:2021-06-10 19:18:21