title: Xamarin Forms Dependency Injection with Microsoft.Extensions.DependencyInjection
body: <p>I am trying to set up basic DI with the standard Microsoft.Extensions.DependencyInjection NuGet package.</p>
  <p>Currently I am registering my dependencies like this:</p>
  <pre><code>public App()
  {
      InitializeComponent();
      var serviceCollection = new ServiceCollection();
      ConfigureServices(serviceCollection);
  }
  
  private static void ConfigureServices(ServiceCollection serviceCollection)
  {
      serviceCollection.AddSingleton&lt;IRestClient&gt;(_ =&gt; new RestClient(&quot;https://localhost:44379/api/&quot;));
      serviceCollection.AddScoped&lt;ICommHubClient, CommHubClient&gt;();
  }
  </code></pre>
  <p>I use a viewModel that requires dependencies like this:</p>
  <pre><code> public ChatListViewModel(
          ICommHubClient client,
          IRestClient restClient
          )
  </code></pre>
  <p>In the code behind file of a page (.xaml.cs) I need to supply the viewModel but I need to provide the dependencies there as well.</p>
  <pre><code>public ChatListPage()
  {
       InitializeComponent();
       BindingContext = _viewModel = new ChatListViewModel(); //CURRENTLY THROWS ERROR BECAUSE NO DEPENDENCIES ARE PASSED!
  }
  </code></pre>
  <p>is there anyone who knows how I can apply Dependency Injection (registering and resolving) with  Microsoft.Extensions.DependencyInjection in Xamarin Forms?</p>