Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dose this support a kotlin android project? #22

Closed
baishuai opened this issue Jan 15, 2017 · 4 comments
Closed

Dose this support a kotlin android project? #22

baishuai opened this issue Jan 15, 2017 · 4 comments

Comments

@baishuai
Copy link

No description provided.

@SaeedMasoumi
Copy link

@baishuai Yes

Here is an example:

@FragmentView(presenter = MyPresenter::class)
class MyFragment : BaseFragment(), MyPresenter.View {

    @Inject
    @Presenter
    lateinit var presenter: MyPresenter

}

class MyPresenter @Inject constructor(val repo: SomeRepository) : AbstractPresenter<MyPresenter.View>() {

 interface View 
}

@baishuai
Copy link
Author

Thanks. @SaeedMasoumi

I have already tried like your example.
And use SomeComponent.inject() before call super.onCreate(savedInstanceState).
But got lateinit property somePresenter has not been initialized

The dagger works ok before I use EasyMVP

Have you ever fall into this problem?

@SaeedMasoumi
Copy link

@baishuai No, Maybe there is a problem with your dagger's component to provide the presenter or you invoke your presenter too early (before Activity#onStart or Fragment#onResume because EasyMVP uses Loaders)

This is my approach to provide a presenter:

  • For each Fragment/Activity, I have a subcomponent
    @Subcomponent(modules = MyModule.class)
    @PerFragment
    interface MyComponent {
        void injectTo(MyFragment fragment);
    }
  • Make presenter constructor injectable
class MyPresenter @Inject constructor(....
  • Before super.onCreate, I inject my dependencies
appComponent.plus(MyModule()).injectTo(this)
  • Now you can use presenter after Activity#onStart or Fragment#onResume

@baishuai
Copy link
Author

Now it works. I have used presenter too early. Thanks very much!

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

No branches or pull requests

2 participants