title: Instantiate ViewModels directly, without making use of ViewModelProviders.of method
body: <p>I have a ViewModel called <code>RecipesViewModel</code>. Usually, I instantiated it this way:</p>
  
  <pre><code>RecipesViewModel viewModel = ViewModelProviders.of(this, new ViewModelProvider.Factory() {
              @Override
              public &lt;T extends ViewModel&gt; T create(Class&lt;T&gt; modelClass) {
                  return (T) new RecipesViewModel(recipesRepository);
              }
          }).get(RecipesViewModel.class);
  </code></pre>
  
  <p>But now I'm using dagger2 and so I put a <code>@Inject</code> annotation on the constructor of this ViewModel, so I'm able to inject it directly in my fragment, using field injector. </p>
  
  <p>My question is: do I lose something starting the viewmodel this way instead of <code>ViewModelProviders.of</code> way? My ViewModel is already Scoped, so only one instance is create in context.</p>
  
  <p>Other option is to move only the factory instantiation to a dagger2 module, but if there is no problem I prefer the first aproach. </p>
  
  <p>-- EDIT --</p>
  
  <p>Reading the documentation <code>android.arch.lifecycle.ViewModel</code>, I'm a little more afraid. Whe use ViewModelProviders.of to provide a Scope (fragment or activity). If I instantiate it directly what will be the Scope?</p>
  
  <blockquote>
    <p>ViewModel is a class that is responsible for preparing and managing
    the data for an Activity or a Fragment. It also handles the
    communication of the Activity / Fragment with the rest of the
    application (e.g. calling the business logic classes).</p>
    
    <p>A ViewModel is always created in association with a scope (an fragment
    or an activity) and will be retained as long as the scope is alive.
    E.g. if it is an Activity, until it is finished.</p>
    
    <p>In other words, this means that a ViewModel will not be destroyed if
    its owner is destroyed for a configuration change (e.g. rotation). The
    new instance of the owner will just re-connected to the existing
    ViewModel.</p>
  </blockquote>
  
  <p>-- /EDIT --</p>
  
  <p>The RecipesViewModel code is showing below: </p>
  
  <pre><code>@PerActivity
  public class RecipesViewModel extends ViewModel {
      private static final String TAG = "RecipesViewModel";
      private final RecipesRepository recipesRepository;
  
      private LiveData&lt;List&lt;Recipe&gt;&gt; recipes = null;
  
      @Inject
      public RecipesViewModel(RecipesRepository recipesRepository) {
          this.recipesRepository = recipesRepository;
      }
  
      public final void loadAll() {
          recipes = recipesRepository.getRecipes();
      }
  
      public LiveData&lt;List&lt;Recipe&gt;&gt; getRecipes() {
          return recipes;
      }
  }
  </code></pre>