Field Injection in Dagger2: DI (Day 2)
<p>In our previous blog post, we discussed the basics of dependency injection and more specifically, constructor injection using Dagger. Today, we’ll explore Field Injection, also known as Members Injection, and discuss when it should be used.</p>
<h1>Introduction</h1>
<p>Field Injection, a form of DI, comes into play when dependencies are directly injected into the fields of a class. This is particularly useful when working with Android’s Activities and Fragments, where the instantiation of a class is out of the developer’s control. In this blog post, we’ll explore Field Injection in detail and learn how to implement it using Dagger2.</p>
<h1>Field Injection in Action</h1>
<p>Let’s apply field injection in our project which we created in the previous post. The first change that we need to make is to annotate our <code>ComputeLayer</code> variable with <code>@Inject</code>. This annotation tells Dagger that we need to field inject it.</p>
<p><a href="https://medium.com/@zuhayr.codes/field-injection-in-dagger2-di-day-2-41b03ecf439a">Read More</a></p>