christmas sale

Flat 10% off on the purchase of any two apps or more. Use coupon code - FESTIVAL10

Grab It Now
Check Mobile App
Read now
Start a Project

Dagger 2 Android implementation

Save

In this blog, we will implement the dagger 2 dependency injection and before we start we will take a look at annotation type which we are going to use in this blog.

Main dagger annotation Types :

Add dependency in your buid.gradle:

1-AppModule.class

AppModule class will be used to provide this reference. We will define a method annotated with @Provides @Singleton that informs Dagger that this method is the constructor for the String return type ( it is the method in charge of providing the instance of the String).

2-AppComponent.class

In AppComponent class where we define the class where we will inject the modules it’s basically the bridge between  Module and the class which injecting the module.

Build your project,  In your MainActivity class to inject the dependency add @Inject annotation on the String object.

I hope it will help you to give the basic idea of how it will make your project component reusable and inject dependency of the object whenever it required by class.

 

 

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

css.php

Great Product, Great Team, and Great Support Service. And if you want to add more features to the product, they can submit any idea that comes to your mind. They really care about their clients and we are really happy and honored to deal with Webkul.

Osama
Talk to Sales

Global

Live Chat
Start a Project

    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home