Dagger: What if I *WANT* a new instance every time?

Dagger: What if I *WANT* a new instance every time?

Content Index :

Dagger: What if I *WANT* a new instance every time?
Tag : android , By : rhinojosa
Date : November 24 2020, 04:01 AM

hop of those help? Dagger will provide you a new instance as long as you don't scope the dependency.
To get a new instance of a dependency manually, you can inject Provider of it instead and use its get() method, it'll give you a new instance every time you call it.
class AppModule {

    fun provideSomeObject(): SomeObject = SomeObject()
class SomeClass {
    // We don't inject the object anymore
    // @Inject lateinit var myObject : SomeObject

    // We'll inject it's provider
    @Inject lateinit var myObject : Provider<SomeObject>

    fun someMethod(){
        // Here, instance1 and instance2 are NOT same objects
        val instance1 = myObject.get()
        val instance2 = myObject.get()

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

error: [Dagger/MissingBinding] [dagger.android.AndroidInjector.inject(T)] Dagger

Tag : java , By : chudq7
Date : March 29 2020, 07:55 AM
hop of those help? You use @inject to annotate the constructor of LoginFragment, when a new instance is requested, Dagger constructs instances of your LoginFragment class and satisfies their dependencies (like the mPresenter field). Because MainActivitySubcomponent doesn’t access LoginFragmentModule, Dagger gives you an error that can not provide LoginContract.Presenter. instead of using constructor injection, if you use another approach for providing LoginFragment for MainActivity, the problem will be solved. You should remove @inject from LoginFragment constructor and create a module to provide it like the following example:
public class MainModule {

    public static LoginFragment provideLoginFragment() {
        return LoginFragment.newInstance("param1", "param2");


Getting null instance from dagger 2

Tag : android , By : kakashi_
Date : March 29 2020, 07:55 AM
should help you out I was passing it wrong in the method of ServicesModule. So I had to pass it in the method like this and it worked:
 fun provideUserService(databaseContext : DatabaseContext()) : UserService = UserService(databaseContext )

How to only have one instance of a Dagger @subcomponent?

Tag : kotlin , By : CHeMoTaCTiC
Date : March 29 2020, 07:55 AM
it fixes the issue You are talking about different question. Lifecycle of object instance should nothing to do with subcomponent. Let me explain here your question.

Dagger injection ViewModel Factory compile time error (dependency cycle in dagger)

Tag : android , By : Lior
Date : March 29 2020, 07:55 AM
seems to work fine I change my providePost method by passing MainActivity as parameter instead of DetailFragment, and problem resolved :
        internal fun providePost(activity: MainActivity): Post {
            val navHostFragment = activity.supportFragmentManager.findFragmentById(R.id.my_nav_host_fragment)
            val fragment = navHostFragment?.childFragmentManager?.fragments?.get(0);
            return DetailFragmentArgs.fromBundle(fragment?.arguments!!).post

Dagger singleton creating new instance every time

Tag : java , By : adbanginwar
Date : March 29 2020, 07:55 AM
will be helpful for those in need In your module you have a method that provides an instance of SoundsRepository - good
In your AppComponent you are missing a:
SoundsRepository soundsRepository();
Global application = (Global) getApplication();
SoundsRepository sr = application.getComponent().soundsRepository()
void inject(PostView postView);
SoundsRepository soundsRepository;
SoundsRepository provideSoundsRepository(Context ........) {
    return new SoundsRepository(...);
Related Posts Related QUESTIONS :
  • Android TextView fontFamily not working when set via TextAppearance
  • Unable to find nearby places
  • Is there any way to launch my application right away without 'Ok Google"?
  • Places api set location biased based on current location
  • Layout Preview is not displaying layout when Material Design is added
  • How do I resolve this diamond problem in Kotlin?
  • How to update the custom value in a view model object
  • How to stop refreshing/re-creating activity when updating Firebase data using setValue?
  • Manifest Permissions vs App Setttings Permissions
  • NumberFormatException in Try-Catch while converting String to Int
  • How to pass observable fields through include tag?
  • Next button on Android keyboard not submitting form
  • Does Firestore support automatic functions for updates?
  • Why app crashing because of a missing dimension (for google maps) only when I apply changes?
  • How to make a grouping, ordering and sorting: Kotlin collection
  • how to use augmented reality to change the color of a qr code once it is detected using with arcore and ml kit firebase
  • how to resolve Firebase projects adding quota problem?
  • Why it Kotlin giving me the wrong Int value when converting from a String
  • How to add bottom navigation listeners to fragments
  • Why is scrollview hiding buttons behind other views?
  • Open Settings using Linking.sendIntent()
  • How do I access an unknown node in firebase while retrieving data?
  • Can't retrieve list of all users from firebase authetication
  • many activities with same content (adview, reward adview, functions...) how to avoid repeating code?
  • Popup doesn't hide when touch outside
  • proper way to handling images in Android? by using Firebase
  • Android: Button is faded gray when it should be transparent
  • Gradle DSL method not found: 'deleteAllActions()'
  • In Clean Architecture, must Repository is Android or Kotlin module?
  • Kotlin parse double from string
  • Inconsistency detected. Invalid view holder adapter positionViewHolder
  • In App Update API always returns 1 (UPDATE_NOT_AVAILABLE)
  • Event of ImageView when click
  • Basic precautions to prevent piracy?
  • What is the difference between 'center' and 'centerCrop' in the "ImageView"?
  • Unable to receive SIP calls when app is killed
  • Android emulator not processing http get request, but iOS simulator works fine
  • Android Problem with sharing temporary file
  • How to add Broadcast in Android?
  • How to hide 'Running in Chrome' toast on TWA application on Android devices?
  • How to Fix Error: Could not find method deleteAllActions() for arguments [] on task
  • Android Deep Linking not working with https
  • WARNING: API 'variant.getMergeResources()' is obsolete and has been replaced with 'variant.getMergeResourcesProvider()'
  • setSupportActionBar (androidx.appcompat.widget.Toolbar) in AppCompatActivity cannot be applied
  • Manifest merger failed after adding Firebase core version 17.0.0
  • Marker from Firestore map data type
  • Cordova signed apk produces a blank screen after splash screen
  • How to clear EditText input from all item views of RecyclerView?
  • Android Studio Mac Fresh install - error after error after error
  • Android Q, programmatically connect to different WiFi AP for internet
  • Application is becoming very slow while retrieving data from server
  • How to get Accelerometer value in Android XAML App(Xamarin.Forms)
  • androidx.constraintlayout.widget.ConstraintLayout cannot be cast to android.widget.TextView
  • Synchronized singleton in Kotlin
  • Product details from barcode
  • What is the difference between armeabi-v7a, arm64-v8a, x86?
  • Where did the "Profile or Debug APK..." option disappear to in Android Studio 3.4.1?
  • App crashes when trying to enter onDataChange Firebase Android
  • Combining WorkContinuation doesn't work as expected
  • Could not get unknown property 'config' for type com.google.gms.googleservices.GoogleServicesPlugin$GoogleServicesPlugin
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com