#4 ViewModelFactory Tutorial -Android ViewModelFactory example-Android Dependency Injection tutorial

preview_player
Показать описание
Today our Topic is ViewModelFactory. ViewModelFactory is a specially designed class which follows the Factory Design pattern and creates ViewModel classes for us.

ViewModelFactory also provides some kind of very simple and modular dependency injection without using any Dependency Framework which is useful for small and medium size project. On a side note, please do not use ViewModelFactory as dependency injection in large projects, use any framework like Dagger or CodeIn instead. So,in this tutorial we will see how to use ViewModelFactory and why particularly it is useful. If you already familiar with Factory Design pattern then it will be easy to understand. But if you not, don’t worry, I have explained the Factory Design pattern later in this tutorial with example.
I demonstrate a super easy and simple way to write your Dependency Injection Implementation which does not require Dagger 2. Using AndroidViewModel, you can write a Dependency Injection Container is a few lines of code.
Since this project uses ViewModelProvider.Factory, I also show you how I wire that up.

#AndroidViewModelFactory
#AndroidViewModelFactoryTutorial
#AndroidViewModelFactoryDependencyInjection
#AndroidAppDevelopmentTutorial
#AndroidDependencyInjection
Рекомендации по теме
Комментарии
Автор

Sir, since we used viewModelFactory to pass data.. so after configuring viewModel with factory why didn't you delete args variable( line no. 45 ) which got data of score using safeargs. please sir explain?. i have confision

sat_talk
Автор

do we need a factory for each of our view models since we pass in argument to the factory?

gregfrllo
Автор

where is Dependency Injection in this.

madhurjain
Автор

hi sir waiting for mvvm login register retrofit video with java

ashrafmakandar
welcome to shbcf.ru