Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Refactor Code #5

Closed
devKshitijJain opened this issue Mar 7, 2018 · 4 comments
Closed

Refactor Code #5

devKshitijJain opened this issue Mar 7, 2018 · 4 comments

Comments

@devKshitijJain
Copy link
Contributor

Here you are calling

DaggerAppComponent.builder()
                .application(this)
                .build()
                .inject(this)

and then you are returning

override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
        return DaggerAppComponent.builder().application(this).build()
    }

can't you just make a var for DaggerAppComponent.builder().application(this).build() and then just call inject on that above.

@skydoves
Copy link
Owner

skydoves commented Mar 7, 2018

Oh you mean like this?

class ApplicationClazz : DaggerApplication() {

    private val appComponent = DaggerAppComponent.builder()
            .application(this)
            .build()

    override fun onCreate() {
        super.onCreate()

        if (!LeakCanary.isInAnalyzerProcess(this)) {
            LeakCanary.install(this)
        }

        if(BuildConfig.DEBUG) {
            Timber.plant(Timber.DebugTree())
        }

        appComponent.inject(this)

        PreferenceComponent_PrefAppComponent.init(this)
    }

    override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
        return appComponent
    }
}

I think it looks better than before too.
Thank you!!

If you want to contribute any codes or change something,
welcome to Pull Request! :)

@devKshitijJain
Copy link
Contributor Author

Let's discuss the approach that you have followed. I think we can make the code more robust and better. Add me on FB @kjain9878

@devKshitijJain
Copy link
Contributor Author

Refactored with PR

@skydoves
Copy link
Owner

skydoves commented Mar 7, 2018

okay, Thanks!!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants