Note: This article assumes some familiarity with Dagger, Anvil, and Kotlin. We use Dagger heavily in the Slack Android app for compile-time dependency injection. It’s powerful, flexible, supports basic Kotlin idioms, and allows for advanced dependency injection patterns with less boilerplate. It’s not without its sharp edges though. It slows down our builds with kapt,…
Overview
This article discusses the extension of Anvil to enhance Dagger dependency injection patterns within the Slack Android app. It highlights the challenges faced with Dagger, the benefits of using Anvil, and provides a detailed implementation example of Activity injection patterns.
What You'll Learn
How to extend Anvil's code generation for custom dependency injection patterns
Why to use Anvil for reducing boilerplate in Dagger dependency injection
When to implement custom Anvil injectors for specific use cases
Prerequisites & Requirements
- Familiarity with Dagger, Anvil, and Kotlin
Key Questions Answered
What are the advantages of using Anvil with Dagger?
How does the custom Anvil injector work for Activity injection?
What challenges does Dagger present in dependency injection?
When should you consider using Anvil in your codebase?
Key Statistics & Figures
Technologies & Tools
Some links below are affiliate links. We may earn a commission if you make a purchase.
Key Actionable Insights
1Implementing Anvil in your project can significantly reduce the boilerplate code associated with Dagger, making your codebase cleaner and easier to maintain.This is particularly beneficial in large projects where dependency injection can become cumbersome, allowing developers to focus on writing functional code rather than managing dependencies.
2Utilizing the compiler API in Anvil enables you to customize code generation to fit your specific needs, which can lead to better performance and reduced build times.This is crucial for teams looking to optimize their build processes and improve developer productivity.