Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
Question: Injection to DFM ViewModel with dagger/hilt
Post Body

Hi, our project is using the VIPER architecture, with each View having its own BUILDER and PRESENTER. The builder is created with a viewmodel and we inject all our dependencies there. The builder then creates the presenter with those dependency.

We initially started off using KOIN as our dependency solution which worked relatively well, but decided to test migrate to dagger/hilt. The migration progress for the APP went relatively smooth as we were able to take advantage of the @ ViewModelInject that Hilt provided. However, I am currently stuck trying to migrate our dynamic feature model to the same structure as the rest of the app.

I am able to follow Google's documentation and create a dagger component to be injected into DFM but i am having extreme difficulty getting the dependencies inject into the viewmodel without creating factory boilerplates for each view's Builder.

Does anyone have any suggestions how i can dynamically create the viewmodels with the injection constructor without having to manually specify in each view?

Here is our base screenview where we initialize our Builder/Presenter:

abstract class ScreenView<BUILDER : ScreenBuilderBase, PRESENTER : ScreenPresenter<out RouterBase>>(u/LayoutRes protected val fragment: Int,private val builderClass: KClass<BUILDER>) : Fragment() {

lateinit var presenter: PRESENTERprotected lateinit var builder: BUILDERvar savedStateViewModelFactory: SavedStateViewModelFactory? = nulloverride fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {return inflater.inflate(fragment, container, false)}

@Suppress("UNCHECKED_CAST")override fun onViewCreated(view: View, savedInstanceState: Bundle?) {super.onViewCreated(view, savedInstanceState)val viewModelProvider: ViewModelProvider =savedStateViewModelFactory?.let { factory: SavedStateViewModelFactory ->ViewModelProvider(this, factory)} ?: ViewModelProvider(this)val builder: BUILDER = logDuration("ViewModelProvider.get(${builderClass.simpleName}}") {viewModelProvider.get(builderClass.java)}builder.setNavController(findNavController())presenter = builder.presenter as PRESENTER}

Author
Account Strength
80%
Account Age
10 years
Verified Email
Yes
Verified Flair
No
Total Karma
421
Link Karma
264
Comment Karma
157
Profile updated: 3 days ago
Posts updated: 7 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
3 years ago