How to inject a ViewModel into BottomSheetDialogFragment with Dagger2?












1















I inject my dependencies in Activities and Fragments on the preferred way with AndroidInjection.inject(this). I have the recommended ViewmodelFactory to inject the viewmodel. My injections are working in Activities and Fragments. However I face a problem with BottomSheetDialogFragment, because I am not allowed to specify BottomSheetDialogFragment as this. So my @Inject lateinit var viewModelFactory: ViewModelFactory is not initialized. I believe that injection should be possible because the BottomSheetDialogFragment should be subclass of the Fragment class, but it looks like it is not. I use android.x which I believe can cause also problem. Is that possible that it is not supported by Dagger yet?



What way should I implement my ViewModelFactory injection?



Update: When I try to inject a fragment with AndroidInjection.inject(this), it is not possible either with the androidx.fragment.app.Fragment only with android.app.Fragement. I extend my Fragments with DaggerFragment and they work as expected.










share|improve this question





























    1















    I inject my dependencies in Activities and Fragments on the preferred way with AndroidInjection.inject(this). I have the recommended ViewmodelFactory to inject the viewmodel. My injections are working in Activities and Fragments. However I face a problem with BottomSheetDialogFragment, because I am not allowed to specify BottomSheetDialogFragment as this. So my @Inject lateinit var viewModelFactory: ViewModelFactory is not initialized. I believe that injection should be possible because the BottomSheetDialogFragment should be subclass of the Fragment class, but it looks like it is not. I use android.x which I believe can cause also problem. Is that possible that it is not supported by Dagger yet?



    What way should I implement my ViewModelFactory injection?



    Update: When I try to inject a fragment with AndroidInjection.inject(this), it is not possible either with the androidx.fragment.app.Fragment only with android.app.Fragement. I extend my Fragments with DaggerFragment and they work as expected.










    share|improve this question



























      1












      1








      1








      I inject my dependencies in Activities and Fragments on the preferred way with AndroidInjection.inject(this). I have the recommended ViewmodelFactory to inject the viewmodel. My injections are working in Activities and Fragments. However I face a problem with BottomSheetDialogFragment, because I am not allowed to specify BottomSheetDialogFragment as this. So my @Inject lateinit var viewModelFactory: ViewModelFactory is not initialized. I believe that injection should be possible because the BottomSheetDialogFragment should be subclass of the Fragment class, but it looks like it is not. I use android.x which I believe can cause also problem. Is that possible that it is not supported by Dagger yet?



      What way should I implement my ViewModelFactory injection?



      Update: When I try to inject a fragment with AndroidInjection.inject(this), it is not possible either with the androidx.fragment.app.Fragment only with android.app.Fragement. I extend my Fragments with DaggerFragment and they work as expected.










      share|improve this question
















      I inject my dependencies in Activities and Fragments on the preferred way with AndroidInjection.inject(this). I have the recommended ViewmodelFactory to inject the viewmodel. My injections are working in Activities and Fragments. However I face a problem with BottomSheetDialogFragment, because I am not allowed to specify BottomSheetDialogFragment as this. So my @Inject lateinit var viewModelFactory: ViewModelFactory is not initialized. I believe that injection should be possible because the BottomSheetDialogFragment should be subclass of the Fragment class, but it looks like it is not. I use android.x which I believe can cause also problem. Is that possible that it is not supported by Dagger yet?



      What way should I implement my ViewModelFactory injection?



      Update: When I try to inject a fragment with AndroidInjection.inject(this), it is not possible either with the androidx.fragment.app.Fragment only with android.app.Fragement. I extend my Fragments with DaggerFragment and they work as expected.







      android dagger-2 bottom-sheet






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 28 '18 at 15:20







      codeme

















      asked Nov 28 '18 at 11:09









      codemecodeme

      149111




      149111
























          2 Answers
          2






          active

          oldest

          votes


















          1














          Here is how I have provided ViewModel into BottomSheetDialogFragment().
          First of all set up Dagger in MyApp class.



          class MyApp : Application(), HasActivityInjector, HasSupportFragmentInjector {

          @Inject
          lateinit var activityInjector: DispatchingAndroidInjector<Activity>
          @Inject
          lateinit var supportFragmentInjector: DispatchingAndroidInjector<Fragment>

          override fun onCreate() {
          super.onCreate()

          initDagger()
          }

          override fun activityInjector(): AndroidInjector<Activity> = activityInjector

          override fun supportFragmentInjector(): AndroidInjector<Fragment> = supportFragmentInjector

          private fun initDagger(){
          DaggerAppComponent
          .builder()
          .application(this)
          .build()
          .injectApp(this)
          }


          Then AppComponent class



          @Singleton
          @Component(
          modules = [
          AppModule::class,
          UiModule::class,
          AndroidSupportInjectionModule::class,
          AndroidInjectionModule::class
          ])interface AppComponent : AndroidInjector<MyApp> {

          @Component.Builder
          interface Builder {
          @BindsInstance
          fun application(application: MyApp): Builder

          fun build(): AppComponent
          }

          fun injectApp(app: MyApp)
          }


          Here we interested in UiModule::class



          @Module
          abstract class UiModule {

          @Binds
          abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory

          @PerFragment
          @ContributesAndroidInjector(modules = [(FilterModule::class)])
          abstract fun contributeFilterFragment(): FilterFragment
          }


          you already have ViewModelFactory , so I don't paste this code.
          Then FilterModule



          @Module
          abstract class FilterModule {

          @Binds
          @IntoMap
          @PerFragment
          @ViewModelKey(FilterViewModel::class)
          abstract fun bindViewModel(viewModel: FilterViewModel): ViewModel
          }


          and finally FilterFragment and FilterViewModel



          class FilterFragment : BottomSheetDialogFragment() {

          @Inject
          lateinit var factory: ViewModelProvider.Factory

          private lateinit var binding: FragmentFilterBinding
          private lateinit var viewModel: FilterViewModel

          override fun onAttach(context: Context?) {
          AndroidSupportInjection.inject(this)
          super.onAttach(context)
          }

          override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
          binding = getDataBinding(inflater, R.layout.fragment_filter, container)
          viewModel = getViewModel(factory)
          binding.viewModel = viewModel
          return binding.root
          }
          }

          class FilterViewModel @Inject constructor(private val testUseCase:TestUseCase) : BaseViewModel() {
          //do something
          }


          fragment_filter layout



          <layout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          xmlns:bind="http://schemas.android.com/tools">

          <data>

          <variable
          name="viewModel"
          type="com.myapp.presentation.screen.filter.FilterViewModel" />
          </data>
          .......


          getDataBinding() and getViewModel() are extension functions



          fun <T : ViewDataBinding> Fragment.getDataBinding(inflater: LayoutInflater, @LayoutRes layoutId: Int, container: ViewGroup?): T =
          DataBindingUtil.inflate(inflater, layoutId, container, false)

          inline fun <reified T : BaseViewModel> Fragment.getViewModel(factory: ViewModelProvider.Factory = ViewModelProviders.DefaultFactory(activity!!.application)): T =
          ViewModelProviders.of(this, factory).get(T::class.java)





          share|improve this answer

































            -1














            Try extending Injectable



            class BottomSheet : BootomSheetDialogFragment(), Injectable 


            I think this will solve the issue






            share|improve this answer
























            • Injectable can not be resolved.

              – codeme
              Nov 28 '18 at 12:29











            • create an interface named Injectable and please let me take a look at your AppInejctor class used for injecting.

              – ABr
              Nov 28 '18 at 13:04











            • why does it help to create a interface Injectable, could you elaborate on that, in your answer?

              – codeme
              Nov 28 '18 at 13:12











            • Did you try the solution?

              – ABr
              Nov 29 '18 at 4:30











            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53518053%2fhow-to-inject-a-viewmodel-into-bottomsheetdialogfragment-with-dagger2%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Here is how I have provided ViewModel into BottomSheetDialogFragment().
            First of all set up Dagger in MyApp class.



            class MyApp : Application(), HasActivityInjector, HasSupportFragmentInjector {

            @Inject
            lateinit var activityInjector: DispatchingAndroidInjector<Activity>
            @Inject
            lateinit var supportFragmentInjector: DispatchingAndroidInjector<Fragment>

            override fun onCreate() {
            super.onCreate()

            initDagger()
            }

            override fun activityInjector(): AndroidInjector<Activity> = activityInjector

            override fun supportFragmentInjector(): AndroidInjector<Fragment> = supportFragmentInjector

            private fun initDagger(){
            DaggerAppComponent
            .builder()
            .application(this)
            .build()
            .injectApp(this)
            }


            Then AppComponent class



            @Singleton
            @Component(
            modules = [
            AppModule::class,
            UiModule::class,
            AndroidSupportInjectionModule::class,
            AndroidInjectionModule::class
            ])interface AppComponent : AndroidInjector<MyApp> {

            @Component.Builder
            interface Builder {
            @BindsInstance
            fun application(application: MyApp): Builder

            fun build(): AppComponent
            }

            fun injectApp(app: MyApp)
            }


            Here we interested in UiModule::class



            @Module
            abstract class UiModule {

            @Binds
            abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory

            @PerFragment
            @ContributesAndroidInjector(modules = [(FilterModule::class)])
            abstract fun contributeFilterFragment(): FilterFragment
            }


            you already have ViewModelFactory , so I don't paste this code.
            Then FilterModule



            @Module
            abstract class FilterModule {

            @Binds
            @IntoMap
            @PerFragment
            @ViewModelKey(FilterViewModel::class)
            abstract fun bindViewModel(viewModel: FilterViewModel): ViewModel
            }


            and finally FilterFragment and FilterViewModel



            class FilterFragment : BottomSheetDialogFragment() {

            @Inject
            lateinit var factory: ViewModelProvider.Factory

            private lateinit var binding: FragmentFilterBinding
            private lateinit var viewModel: FilterViewModel

            override fun onAttach(context: Context?) {
            AndroidSupportInjection.inject(this)
            super.onAttach(context)
            }

            override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
            binding = getDataBinding(inflater, R.layout.fragment_filter, container)
            viewModel = getViewModel(factory)
            binding.viewModel = viewModel
            return binding.root
            }
            }

            class FilterViewModel @Inject constructor(private val testUseCase:TestUseCase) : BaseViewModel() {
            //do something
            }


            fragment_filter layout



            <layout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:bind="http://schemas.android.com/tools">

            <data>

            <variable
            name="viewModel"
            type="com.myapp.presentation.screen.filter.FilterViewModel" />
            </data>
            .......


            getDataBinding() and getViewModel() are extension functions



            fun <T : ViewDataBinding> Fragment.getDataBinding(inflater: LayoutInflater, @LayoutRes layoutId: Int, container: ViewGroup?): T =
            DataBindingUtil.inflate(inflater, layoutId, container, false)

            inline fun <reified T : BaseViewModel> Fragment.getViewModel(factory: ViewModelProvider.Factory = ViewModelProviders.DefaultFactory(activity!!.application)): T =
            ViewModelProviders.of(this, factory).get(T::class.java)





            share|improve this answer






























              1














              Here is how I have provided ViewModel into BottomSheetDialogFragment().
              First of all set up Dagger in MyApp class.



              class MyApp : Application(), HasActivityInjector, HasSupportFragmentInjector {

              @Inject
              lateinit var activityInjector: DispatchingAndroidInjector<Activity>
              @Inject
              lateinit var supportFragmentInjector: DispatchingAndroidInjector<Fragment>

              override fun onCreate() {
              super.onCreate()

              initDagger()
              }

              override fun activityInjector(): AndroidInjector<Activity> = activityInjector

              override fun supportFragmentInjector(): AndroidInjector<Fragment> = supportFragmentInjector

              private fun initDagger(){
              DaggerAppComponent
              .builder()
              .application(this)
              .build()
              .injectApp(this)
              }


              Then AppComponent class



              @Singleton
              @Component(
              modules = [
              AppModule::class,
              UiModule::class,
              AndroidSupportInjectionModule::class,
              AndroidInjectionModule::class
              ])interface AppComponent : AndroidInjector<MyApp> {

              @Component.Builder
              interface Builder {
              @BindsInstance
              fun application(application: MyApp): Builder

              fun build(): AppComponent
              }

              fun injectApp(app: MyApp)
              }


              Here we interested in UiModule::class



              @Module
              abstract class UiModule {

              @Binds
              abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory

              @PerFragment
              @ContributesAndroidInjector(modules = [(FilterModule::class)])
              abstract fun contributeFilterFragment(): FilterFragment
              }


              you already have ViewModelFactory , so I don't paste this code.
              Then FilterModule



              @Module
              abstract class FilterModule {

              @Binds
              @IntoMap
              @PerFragment
              @ViewModelKey(FilterViewModel::class)
              abstract fun bindViewModel(viewModel: FilterViewModel): ViewModel
              }


              and finally FilterFragment and FilterViewModel



              class FilterFragment : BottomSheetDialogFragment() {

              @Inject
              lateinit var factory: ViewModelProvider.Factory

              private lateinit var binding: FragmentFilterBinding
              private lateinit var viewModel: FilterViewModel

              override fun onAttach(context: Context?) {
              AndroidSupportInjection.inject(this)
              super.onAttach(context)
              }

              override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
              binding = getDataBinding(inflater, R.layout.fragment_filter, container)
              viewModel = getViewModel(factory)
              binding.viewModel = viewModel
              return binding.root
              }
              }

              class FilterViewModel @Inject constructor(private val testUseCase:TestUseCase) : BaseViewModel() {
              //do something
              }


              fragment_filter layout



              <layout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:app="http://schemas.android.com/apk/res-auto"
              xmlns:bind="http://schemas.android.com/tools">

              <data>

              <variable
              name="viewModel"
              type="com.myapp.presentation.screen.filter.FilterViewModel" />
              </data>
              .......


              getDataBinding() and getViewModel() are extension functions



              fun <T : ViewDataBinding> Fragment.getDataBinding(inflater: LayoutInflater, @LayoutRes layoutId: Int, container: ViewGroup?): T =
              DataBindingUtil.inflate(inflater, layoutId, container, false)

              inline fun <reified T : BaseViewModel> Fragment.getViewModel(factory: ViewModelProvider.Factory = ViewModelProviders.DefaultFactory(activity!!.application)): T =
              ViewModelProviders.of(this, factory).get(T::class.java)





              share|improve this answer




























                1












                1








                1







                Here is how I have provided ViewModel into BottomSheetDialogFragment().
                First of all set up Dagger in MyApp class.



                class MyApp : Application(), HasActivityInjector, HasSupportFragmentInjector {

                @Inject
                lateinit var activityInjector: DispatchingAndroidInjector<Activity>
                @Inject
                lateinit var supportFragmentInjector: DispatchingAndroidInjector<Fragment>

                override fun onCreate() {
                super.onCreate()

                initDagger()
                }

                override fun activityInjector(): AndroidInjector<Activity> = activityInjector

                override fun supportFragmentInjector(): AndroidInjector<Fragment> = supportFragmentInjector

                private fun initDagger(){
                DaggerAppComponent
                .builder()
                .application(this)
                .build()
                .injectApp(this)
                }


                Then AppComponent class



                @Singleton
                @Component(
                modules = [
                AppModule::class,
                UiModule::class,
                AndroidSupportInjectionModule::class,
                AndroidInjectionModule::class
                ])interface AppComponent : AndroidInjector<MyApp> {

                @Component.Builder
                interface Builder {
                @BindsInstance
                fun application(application: MyApp): Builder

                fun build(): AppComponent
                }

                fun injectApp(app: MyApp)
                }


                Here we interested in UiModule::class



                @Module
                abstract class UiModule {

                @Binds
                abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory

                @PerFragment
                @ContributesAndroidInjector(modules = [(FilterModule::class)])
                abstract fun contributeFilterFragment(): FilterFragment
                }


                you already have ViewModelFactory , so I don't paste this code.
                Then FilterModule



                @Module
                abstract class FilterModule {

                @Binds
                @IntoMap
                @PerFragment
                @ViewModelKey(FilterViewModel::class)
                abstract fun bindViewModel(viewModel: FilterViewModel): ViewModel
                }


                and finally FilterFragment and FilterViewModel



                class FilterFragment : BottomSheetDialogFragment() {

                @Inject
                lateinit var factory: ViewModelProvider.Factory

                private lateinit var binding: FragmentFilterBinding
                private lateinit var viewModel: FilterViewModel

                override fun onAttach(context: Context?) {
                AndroidSupportInjection.inject(this)
                super.onAttach(context)
                }

                override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
                binding = getDataBinding(inflater, R.layout.fragment_filter, container)
                viewModel = getViewModel(factory)
                binding.viewModel = viewModel
                return binding.root
                }
                }

                class FilterViewModel @Inject constructor(private val testUseCase:TestUseCase) : BaseViewModel() {
                //do something
                }


                fragment_filter layout



                <layout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                xmlns:bind="http://schemas.android.com/tools">

                <data>

                <variable
                name="viewModel"
                type="com.myapp.presentation.screen.filter.FilterViewModel" />
                </data>
                .......


                getDataBinding() and getViewModel() are extension functions



                fun <T : ViewDataBinding> Fragment.getDataBinding(inflater: LayoutInflater, @LayoutRes layoutId: Int, container: ViewGroup?): T =
                DataBindingUtil.inflate(inflater, layoutId, container, false)

                inline fun <reified T : BaseViewModel> Fragment.getViewModel(factory: ViewModelProvider.Factory = ViewModelProviders.DefaultFactory(activity!!.application)): T =
                ViewModelProviders.of(this, factory).get(T::class.java)





                share|improve this answer















                Here is how I have provided ViewModel into BottomSheetDialogFragment().
                First of all set up Dagger in MyApp class.



                class MyApp : Application(), HasActivityInjector, HasSupportFragmentInjector {

                @Inject
                lateinit var activityInjector: DispatchingAndroidInjector<Activity>
                @Inject
                lateinit var supportFragmentInjector: DispatchingAndroidInjector<Fragment>

                override fun onCreate() {
                super.onCreate()

                initDagger()
                }

                override fun activityInjector(): AndroidInjector<Activity> = activityInjector

                override fun supportFragmentInjector(): AndroidInjector<Fragment> = supportFragmentInjector

                private fun initDagger(){
                DaggerAppComponent
                .builder()
                .application(this)
                .build()
                .injectApp(this)
                }


                Then AppComponent class



                @Singleton
                @Component(
                modules = [
                AppModule::class,
                UiModule::class,
                AndroidSupportInjectionModule::class,
                AndroidInjectionModule::class
                ])interface AppComponent : AndroidInjector<MyApp> {

                @Component.Builder
                interface Builder {
                @BindsInstance
                fun application(application: MyApp): Builder

                fun build(): AppComponent
                }

                fun injectApp(app: MyApp)
                }


                Here we interested in UiModule::class



                @Module
                abstract class UiModule {

                @Binds
                abstract fun bindViewModelFactory(factory: ViewModelFactory): ViewModelProvider.Factory

                @PerFragment
                @ContributesAndroidInjector(modules = [(FilterModule::class)])
                abstract fun contributeFilterFragment(): FilterFragment
                }


                you already have ViewModelFactory , so I don't paste this code.
                Then FilterModule



                @Module
                abstract class FilterModule {

                @Binds
                @IntoMap
                @PerFragment
                @ViewModelKey(FilterViewModel::class)
                abstract fun bindViewModel(viewModel: FilterViewModel): ViewModel
                }


                and finally FilterFragment and FilterViewModel



                class FilterFragment : BottomSheetDialogFragment() {

                @Inject
                lateinit var factory: ViewModelProvider.Factory

                private lateinit var binding: FragmentFilterBinding
                private lateinit var viewModel: FilterViewModel

                override fun onAttach(context: Context?) {
                AndroidSupportInjection.inject(this)
                super.onAttach(context)
                }

                override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
                binding = getDataBinding(inflater, R.layout.fragment_filter, container)
                viewModel = getViewModel(factory)
                binding.viewModel = viewModel
                return binding.root
                }
                }

                class FilterViewModel @Inject constructor(private val testUseCase:TestUseCase) : BaseViewModel() {
                //do something
                }


                fragment_filter layout



                <layout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                xmlns:bind="http://schemas.android.com/tools">

                <data>

                <variable
                name="viewModel"
                type="com.myapp.presentation.screen.filter.FilterViewModel" />
                </data>
                .......


                getDataBinding() and getViewModel() are extension functions



                fun <T : ViewDataBinding> Fragment.getDataBinding(inflater: LayoutInflater, @LayoutRes layoutId: Int, container: ViewGroup?): T =
                DataBindingUtil.inflate(inflater, layoutId, container, false)

                inline fun <reified T : BaseViewModel> Fragment.getViewModel(factory: ViewModelProvider.Factory = ViewModelProviders.DefaultFactory(activity!!.application)): T =
                ViewModelProviders.of(this, factory).get(T::class.java)






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 29 '18 at 15:59

























                answered Nov 29 '18 at 15:46









                Alexandr SushkovAlexandr Sushkov

                777




                777

























                    -1














                    Try extending Injectable



                    class BottomSheet : BootomSheetDialogFragment(), Injectable 


                    I think this will solve the issue






                    share|improve this answer
























                    • Injectable can not be resolved.

                      – codeme
                      Nov 28 '18 at 12:29











                    • create an interface named Injectable and please let me take a look at your AppInejctor class used for injecting.

                      – ABr
                      Nov 28 '18 at 13:04











                    • why does it help to create a interface Injectable, could you elaborate on that, in your answer?

                      – codeme
                      Nov 28 '18 at 13:12











                    • Did you try the solution?

                      – ABr
                      Nov 29 '18 at 4:30
















                    -1














                    Try extending Injectable



                    class BottomSheet : BootomSheetDialogFragment(), Injectable 


                    I think this will solve the issue






                    share|improve this answer
























                    • Injectable can not be resolved.

                      – codeme
                      Nov 28 '18 at 12:29











                    • create an interface named Injectable and please let me take a look at your AppInejctor class used for injecting.

                      – ABr
                      Nov 28 '18 at 13:04











                    • why does it help to create a interface Injectable, could you elaborate on that, in your answer?

                      – codeme
                      Nov 28 '18 at 13:12











                    • Did you try the solution?

                      – ABr
                      Nov 29 '18 at 4:30














                    -1












                    -1








                    -1







                    Try extending Injectable



                    class BottomSheet : BootomSheetDialogFragment(), Injectable 


                    I think this will solve the issue






                    share|improve this answer













                    Try extending Injectable



                    class BottomSheet : BootomSheetDialogFragment(), Injectable 


                    I think this will solve the issue







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 28 '18 at 12:19









                    ABrABr

                    331211




                    331211













                    • Injectable can not be resolved.

                      – codeme
                      Nov 28 '18 at 12:29











                    • create an interface named Injectable and please let me take a look at your AppInejctor class used for injecting.

                      – ABr
                      Nov 28 '18 at 13:04











                    • why does it help to create a interface Injectable, could you elaborate on that, in your answer?

                      – codeme
                      Nov 28 '18 at 13:12











                    • Did you try the solution?

                      – ABr
                      Nov 29 '18 at 4:30



















                    • Injectable can not be resolved.

                      – codeme
                      Nov 28 '18 at 12:29











                    • create an interface named Injectable and please let me take a look at your AppInejctor class used for injecting.

                      – ABr
                      Nov 28 '18 at 13:04











                    • why does it help to create a interface Injectable, could you elaborate on that, in your answer?

                      – codeme
                      Nov 28 '18 at 13:12











                    • Did you try the solution?

                      – ABr
                      Nov 29 '18 at 4:30

















                    Injectable can not be resolved.

                    – codeme
                    Nov 28 '18 at 12:29





                    Injectable can not be resolved.

                    – codeme
                    Nov 28 '18 at 12:29













                    create an interface named Injectable and please let me take a look at your AppInejctor class used for injecting.

                    – ABr
                    Nov 28 '18 at 13:04





                    create an interface named Injectable and please let me take a look at your AppInejctor class used for injecting.

                    – ABr
                    Nov 28 '18 at 13:04













                    why does it help to create a interface Injectable, could you elaborate on that, in your answer?

                    – codeme
                    Nov 28 '18 at 13:12





                    why does it help to create a interface Injectable, could you elaborate on that, in your answer?

                    – codeme
                    Nov 28 '18 at 13:12













                    Did you try the solution?

                    – ABr
                    Nov 29 '18 at 4:30





                    Did you try the solution?

                    – ABr
                    Nov 29 '18 at 4:30


















                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53518053%2fhow-to-inject-a-viewmodel-into-bottomsheetdialogfragment-with-dagger2%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

                    Calculate evaluation metrics using cross_val_predict sklearn

                    Insert data from modal to MySQL (multiple modal on website)