# dagger-2

Published articles for dagger-2.

This is one page of public article previews, not the complete archive. Follow Next page to continue. Summaries are not the original full articles.

## Dagger Tips: Guide to using Dagger-Android effectively

DevFeed: [Dagger Tips: Guide to using Dagger-Android effectively](<https://devfeed.tech/articles/dagger-tips-guide-to-using-dagger-android-effectively-25929.md>)

Original publisher: [Read original article](<https://itnext.io/dagger-tips-guide-to-using-dagger-android-effectively-c3e5b2883b38?source=rss-7a8d96da8cb6------2>)

Author: Gabor Varadi

Published: 2021-02-13T05:05:50Z

Content type: tutorial

Language: en

Sources: [Stories by Gabor Varadi on Medium](<https://devfeed.tech/sources/stories-by-gabor-varadi-on-medium.md>)

Topics: [Dagger](<https://devfeed.tech/topics/dagger.md>), [Android](<https://devfeed.tech/topics/android.md>), [Architecture & Design](<https://devfeed.tech/topics/architecture-design.md>), [Development](<https://devfeed.tech/topics/development.md>), [Scalability](<https://devfeed.tech/topics/scalability.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [dagger-2](<https://devfeed.tech/tags/dagger-2.md>), [dagger-android](<https://devfeed.tech/tags/dagger-android.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [development](<https://devfeed.tech/tags/development.md>), [guide](<https://devfeed.tech/tags/guide.md>), [interface](<https://devfeed.tech/tags/interface.md>), [modularization](<https://devfeed.tech/tags/modularization.md>), [module](<https://devfeed.tech/tags/module.md>), [scalability](<https://devfeed.tech/tags/scalability.md>)

### AI overview

A guide to using Dagger-Android, explaining its field-injection approach, the modularization constraints it addresses, and alternatives involving interfaces or shared superclasses. The article notes that Dagger-Android has been superseded by Hilt for common injection cases.

### Source excerpt

Something people could ask me as they're reading this title: "Hold on a second, isn't Dagger-Android no longer in active development? Isn't it made obsolete with the introduction of Hilt?" Technically, yes. Dagger-Android is superseded by Hilt. So there is a good chance that if you are already using Hilt, then for the most common cases (injecting Activity, Fragment, ViewModel, Worker), you don't need to think about Dagger-Android whatsoever. However, as I still see @ContributesAndroidInjector popping up every now and then, I feel that it's best if I write an article on how it works, what it intended to solve, how to use it, and how NOT to use it (for better scalability). What was Dagger-Android? Dagger-Android was a way to field-inject classes (not necessarily just Android classes since Dagger 2.20+) without having to define a fun inject(target: MyConcreteClassTarget) injector method on the component -- as we don't know the class itself. When do you want to avoid creating fun inject(t: T) in a component? After all, this is what normally allows field injection to be type-safe. The answer is, when you can't. If you use a modularization pattern where :app contains the ApplicationComponent(or SingletonComponent), then while ApplicationComponent can see any Activity or Fragment within the app, the submodules don't see :app and therefore don't see ApplicationComponent. Therefore, they can't call component.inject(this)! On the other hand, if you were to define an Application.ActivityLifecycleCallbacks to do it automatically, that wouldn't work with the standard approach -- as you see only the superclass, but not the concrete class! So if one wants to use field injection with our provided restrictions, there are two options: Expose an interface from the child module that defines the injection targets, and implement that on the ApplicationComponent -- then make it possible to access it (for example, using the ApplicationContext for lookup) and cast it to the interface to be abl

## Structural and navigation anti-patterns in modularized Android applications

DevFeed: [Structural and navigation anti-patterns in modularized Android applications](<https://devfeed.tech/articles/structural-and-navigation-anti-patterns-in-modularized-android-applications-25933.md>)

Original publisher: [Read original article](<https://proandroiddev.com/structural-and-navigation-anti-patterns-in-modularized-android-applications-a7d667e35cd6?source=rss-7a8d96da8cb6------2>)

Author: Gabor Varadi

Published: 2020-12-25T11:38:05Z

Content type: article

Language: en

Sources: [Stories by Gabor Varadi on Medium](<https://devfeed.tech/sources/stories-by-gabor-varadi-on-medium.md>)

Topics: [Android](<https://devfeed.tech/topics/android.md>), [Gradle](<https://devfeed.tech/topics/gradle.md>), [modules](<https://devfeed.tech/topics/modules.md>), [navigation](<https://devfeed.tech/topics/navigation.md>), [Code](<https://devfeed.tech/topics/code.md>), [Dagger](<https://devfeed.tech/topics/dagger.md>), [Dependency injection](<https://devfeed.tech/topics/dependency-injection.md>), [RxJava](<https://devfeed.tech/topics/rxjava.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [android-app-development](<https://devfeed.tech/tags/android-app-development.md>), [antipattern](<https://devfeed.tech/tags/antipattern.md>), [architecture](<https://devfeed.tech/tags/architecture.md>), [clean-architecture](<https://devfeed.tech/tags/clean-architecture.md>), [code](<https://devfeed.tech/tags/code.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [dagger-2](<https://devfeed.tech/tags/dagger-2.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [domain-driven-design](<https://devfeed.tech/tags/domain-driven-design.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [modularization](<https://devfeed.tech/tags/modularization.md>), [modules](<https://devfeed.tech/tags/modules.md>), [navigation](<https://devfeed.tech/tags/navigation.md>), [navigation-architecture](<https://devfeed.tech/tags/navigation-architecture.md>), [rxjava](<https://devfeed.tech/tags/rxjava.md>)

### AI overview

This article examines structural and navigation anti-patterns in modularized Android applications. It traces the history of Android Clean Architecture and argues that organizing an application around top-level data, domain, and presentation modules can be problematic, particularly when the structure is adopted from educational examples rather than feature-based organization.

### Source excerpt

Structural and navigation anti-patterns in multi-module and modularized applications: The case against "Android Clean Architecture" and the "domain" moduleTop-level "domain" module is a code smell. Merry Christmas to all! The subject of this article is one that has been on my mind for a very long time. After all, "Clean Architecture" is often seen as the end goal, the hallmark of the finest of Android application code structure -- it is the best of the very best. The name itself, "Clean Architecture", signals that it's a good thing ~ after all, who wants to work with "messy" code in comparison? Of course, the title of this article shows that this isn't the conclusion we'll come to. The following tweet is closer to our final evaluation -- let us analyze why it might be accurate. Clean architecture + Android for us was like building a beautiful sailing boat in your backyard because someone on TV convinced you it's better for crossing the sea than an inflatable, while you live in the mountains and also your house is on fire. https://t.co/iGqy25wk7m The history of "Android Clean Architecture"The origins To understand "Clean Architecture" as done on Android, we must trace it back to its roots, and where/when it was made popular in the first place. As far as I'm aware, it dates back to 2014, the original proposition in "Fernando Cejas: Architecting Android... the clean way?". It was a highly influential article, as it revolutionized the structure of Android apps. Code that is actually separated across layers (back when Fragments were untrustworthy, and all code was in OS-level components), rather than just throwing everything into 2000+ line Activities? A pioneer of its time. One interesting decision however in the representative sample code was that in order to signify the strict separation of layers, these layers were each separated from one another using top-level Gradle modules, each labeled data, domain, and presentation. As we will see, this is the downfall of the sampl

## The Corner Round-up June 2020

DevFeed: [The Corner Round-up June 2020](<https://devfeed.tech/articles/the-corner-round-up-june-2020-27019.md>)

Original publisher: [Read original article](<https://medium.com/square-corner-blog/the-corner-round-up-june-2020-5f0eaa1d341e?source=rss----3650599ae4e2---4>)

Author: Richard Moot

Published: 2020-06-30T22:59:20Z

Content type: article

Language: en

Sources: [Square Corner Blog - Medium](<https://devfeed.tech/sources/square-corner-blog-medium.md>)

Topics: [API](<https://devfeed.tech/topics/api.md>), [Dependency injection](<https://devfeed.tech/topics/dependency-injection.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Dagger](<https://devfeed.tech/topics/dagger.md>), [Kubernetes](<https://devfeed.tech/topics/kubernetes.md>)

Tags: [api](<https://devfeed.tech/tags/api.md>), [apis](<https://devfeed.tech/tags/apis.md>), [cloud](<https://devfeed.tech/tags/cloud.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [dagger-2](<https://devfeed.tech/tags/dagger-2.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [kubernetes](<https://devfeed.tech/tags/kubernetes.md>), [payments](<https://devfeed.tech/tags/payments.md>), [pos](<https://devfeed.tech/tags/pos.md>), [security](<https://devfeed.tech/tags/security.md>)

### AI overview

The Corner Round-up June 2020 recaps selected publications from Square's developer blog. It covers the Square Team API, the Hephaestus open source compiler plugin for Dagger 2, API Explorer's move from beta to general availability, Kubernetes pod security guidance, Loyalty and Customers APIs, and the Square Terminal API beta.

### Source excerpt

In order to keep some of the followers still here on Medium, we wanted to provide a quick recap on some of the things that have been published over at The Corner Blog's new home https://developer.squareup.com/blog (in case you didn't know that already). We'll just be doing a quick summary of each new thing, but you can check out each topic in detail over at our new home. Manage Team Data from Any Platform with Square Team API We released a new Team API to allow managing Team data from any platform. You can track and edit large volumes of team member data automatically and synchronize data with any third-party platform in real time! Introducing Hephaestus In order to make dependency injection with Dagger 2 easier, we had created Hephaestus. It is an open source compiler plugin that automatically merges Dagger modules and component interfaces to make development more enjoyable. API Explorer Moves to General Availability The Square Developer team also transitioned the API Explorer from Beta to GA, bringing with it a lot of improvements to make testing Square APIs much more enjoyable and easy. Kubernetes - Pod Security Policies The cloud team at Square also did a write-up that provides some useful guidance and examples for handling Pod Security in Kubernetes. Reward Customers Wherever They Shop with Loyalty API and Customers API Additionally, Square Loyalty now has an API to make providing rewards to customers on other platforms. Using the Customers API and Loyalty API in combination can allow any developer to create a great rewards system, no matter where their customers are. Announcing Square Terminal API Beta Finally, we also released Terminal API, which lets you programmatically take payments using Square Terminal. This API allows developers to connect Square Terminal, an all-in-one card payments device, to their custom-built POS systems, no matter which platforms or operating systems they're developed on. Now that isn't everything that we've published since you've

## Introducing Anvil

DevFeed: [Introducing Anvil](<https://devfeed.tech/articles/introducing-anvil-15698.md>)

Original publisher: [Read original article](<https://developer.squareup.com/blog/introducing-anvil>)

Author: Ralf Wondratschek

Published: 2020-06-23T19:00:00Z

Content type: article

Language: en

Sources: [Square Corner Blog RSS Feed](<https://devfeed.tech/sources/square-corner-blog-rss-feed.md>)

Topics: [Dagger](<https://devfeed.tech/topics/dagger.md>), [Dependency injection](<https://devfeed.tech/topics/dependency-injection.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Android](<https://devfeed.tech/topics/android.md>), [Gradle](<https://devfeed.tech/topics/gradle.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [dagger-2](<https://devfeed.tech/tags/dagger-2.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>)

### AI overview

Square introduces Anvil, a Kotlin compiler plugin that automatically adds Dagger modules and component interfaces to required Dagger components. The tool reduces repetitive setup steps in large modularized Android codebases while preserving compile-time dependency graph validation.

### Source excerpt

Make dependency injection with Dagger 2 easier

## Keeping the Daggers Sharp

DevFeed: [Keeping the Daggers Sharp](<https://devfeed.tech/articles/keeping-the-daggers-sharp-15734.md>)

Original publisher: [Read original article](<https://developer.squareup.com/blog/keeping-the-daggers-sharp>)

Author: P-Y Ricau

Published: 2017-10-11T17:41:33Z

Content type: tutorial

Language: en

Sources: [Square Corner Blog RSS Feed](<https://devfeed.tech/sources/square-corner-blog-rss-feed.md>)

Topics: [Dagger](<https://devfeed.tech/topics/dagger.md>), [Dependency injection](<https://devfeed.tech/topics/dependency-injection.md>), [Android](<https://devfeed.tech/topics/android.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Library](<https://devfeed.tech/topics/library.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [dagger-2](<https://devfeed.tech/tags/dagger-2.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [library](<https://devfeed.tech/tags/library.md>), [performance](<https://devfeed.tech/tags/performance.md>)

### AI overview

This article presents practical Dagger 2 dependency-injection guidance for Android development. It discusses field and constructor injection, singleton and scoping choices, static Dagger methods, abstract modules, and interface-to-implementation bindings, while noting that the recommendations depend on team context.

### Source excerpt

Dagger 2 is a great dependency injection library, but its sharp edges can be tricky to handle. Let's go over a few best practices that...

## How to use Dagger 2 on Android with Kotlin (KAD 20)

DevFeed: [How to use Dagger 2 on Android with Kotlin (KAD 20)](<https://devfeed.tech/articles/how-to-use-dagger-2-on-android-with-kotlin-kad-20-27152.md>)

Original publisher: [Read original article](<https://antonioleiva.com/dagger-android-kotlin>)

Published: 2017-04-11T00:00:00Z

Content type: tutorial

Language: en

Sources: [Antonio Leiva](<https://devfeed.tech/sources/antonio-leiva.md>)

Topics: [Dagger](<https://devfeed.tech/topics/dagger.md>), [Android](<https://devfeed.tech/topics/android.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Dependency injection](<https://devfeed.tech/topics/dependency-injection.md>)

Tags: [android](<https://devfeed.tech/tags/android.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [dagger-2](<https://devfeed.tech/tags/dagger-2.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>)

### AI overview

A tutorial on configuring Dagger 2 in an Android project using Kotlin. It covers Kotlin-specific setup, compiler and library dependencies, and implementing the application module and main dependency-injection graph.

### Source excerpt

Everything Android, Kotlin and other random topics

## Introducing Cleanse: A Lightweight Dependency Injection Framework For Swift

DevFeed: [Introducing Cleanse: A Lightweight Dependency Injection Framework For Swift](<https://devfeed.tech/articles/introducing-cleanse-a-lightweight-dependency-injection-framework-for-swift-15701.md>)

Original publisher: [Read original article](<https://developer.squareup.com/blog/introducing-cleanse-a-lightweight-dependency-injection-framework-for-swift>)

Author: Square Engineering

Published: 2016-06-14T16:11:00Z

Content type: release

Language: en

Sources: [Square Corner Blog RSS Feed](<https://devfeed.tech/sources/square-corner-blog-rss-feed.md>)

Topics: [Dependency injection](<https://devfeed.tech/topics/dependency-injection.md>), [Swift](<https://devfeed.tech/topics/swift.md>), [Library](<https://devfeed.tech/topics/library.md>), [Dagger](<https://devfeed.tech/topics/dagger.md>), [Java](<https://devfeed.tech/topics/java.md>), [Code generation](<https://devfeed.tech/topics/code-generation.md>), [iOS](<https://devfeed.tech/topics/ios.md>)

Tags: [code-generation](<https://devfeed.tech/tags/code-generation.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [dagger-2](<https://devfeed.tech/tags/dagger-2.md>), [dependency-injection](<https://devfeed.tech/tags/dependency-injection.md>), [engineering](<https://devfeed.tech/tags/engineering.md>), [ios](<https://devfeed.tech/tags/ios.md>), [library](<https://devfeed.tech/tags/library.md>), [objective-c](<https://devfeed.tech/tags/objective-c.md>), [swift](<https://devfeed.tech/tags/swift.md>)

### AI overview

The article introduces Cleanse, a pure Swift dependency injection library. It explains the limitations of the authors' earlier Objective-C and code-generation approach and describes how Cleanse uses Swift's type system to provide compile-time safety and a feature set inspired by Guice and Dagger 2.

### Source excerpt

Cleanse is a pure Swift dependency injection library.

## Using Dagger 1 and Kotlin

DevFeed: [Using Dagger 1 and Kotlin](<https://devfeed.tech/articles/using-dagger-1-and-kotlin-25103.md>)

Original publisher: [Read original article](<http://michaelevans.org/blog/2016/02/17/using-dagger-1-and-kotlin/>)

Author: Michael Evans

Published: 2016-02-17T18:43:25Z

Content type: article

Language: en

Sources: [Gadget Habit](<https://devfeed.tech/sources/gadget-habit.md>)

Topics: [Dagger](<https://devfeed.tech/topics/dagger.md>), [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [Android](<https://devfeed.tech/topics/android.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Development](<https://devfeed.tech/topics/development.md>)

Tags: [2](<https://devfeed.tech/tags/2.md>), [android](<https://devfeed.tech/tags/android.md>), [android-development](<https://devfeed.tech/tags/android-development.md>), [beginner](<https://devfeed.tech/tags/beginner.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [dagger](<https://devfeed.tech/tags/dagger.md>), [dagger-2](<https://devfeed.tech/tags/dagger-2.md>), [dependencies](<https://devfeed.tech/tags/dependencies.md>), [development](<https://devfeed.tech/tags/development.md>), [di](<https://devfeed.tech/tags/di.md>), [java](<https://devfeed.tech/tags/java.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [property](<https://devfeed.tech/tags/property.md>)

### AI overview

This article explains how to use Dagger 1 with Kotlin in an Android app. It describes Kotlin annotation-processing limitations, Dagger module compilation problems, and a workaround that converts modules to Java classes. It also explains how to inject Kotlin properties by targeting the annotation at the backing field because Dagger does not support method injection.

### Source excerpt

Unless you've been hiding from all the news about Android development, you've likely heard about Kotlin (which hit version 1.0 on Monday!). I've been toying around with it lately (the Kotlin Koans are a great place to start for a beginner) and wanted to try building an app with it - that is, until I hit a few road blocks. Personally, I'm still a fan of Dagger 1 (or as I refer to it, Dagger Classic), and when I started working on my Kotlin app, that's what I was planning to use. I knew Annotation Processing support was a relatively new addition to Kotlin, so I began to search for some information about how to get Dagger to play nicely with the Kotlin compiler. There's a lot of information about using Dagger 2 with Kotlin but not so much about Dagger Classic. Finally, I stumbled upon this article, which said, "Unfortunately, Square's Dagger 1 does not appear to work with Kotlin while Google's Dagger 2 does". Bummer. This didn't really deter me, however, because I'm stubborn like that. So I proceeded to give it a try with kapt1 anyway (which seemed like it might do what I want). Modules The first thing I did was try to create the various Dagger Modules that I'd need, which is where I hit my first roadblock. Attempting to compile my module gave the following error: 1 Error:Modules must not extend from other classes: org.michaelevans.example.AppModule My intial thought was that Kotlin was causing my Module to extend Any, rather than Object. (Any is the root of the class hierarchy in Kotlin, similar to the way that Object is the root of the Java class hierarchy.) Upon closer inspection, that didn't seem to be the issue, but rather than get hung up on this - I just converted my modules to Java classes and decided to come back to this issue later. @Inject So now I had my modules set up, and I went about trying to @Inject some fields on an Activity or two. This yielded another problem: Kotlin doesn't have fields, and we obviously can't do constructor injection on something f