title: How to use dependency injection in an UWP app?
body: <p>I am using autofac in an UWP application. In my <code>App</code> instance, I am setting up the dependency, like this:</p>
  
  <pre><code>public sealed partial class App
  {
     private readonly IFacade m_facade;
  
     public App()
     {
         InitializeComponent();
  
         m_facade = InitializeDependencies();
  
         Suspending += OnSuspending;
     }
  
     private IFacade InitializeDependencies()
     {
         var containerBuilder = new ContainerBuilder();
  
         //  Registers all the platform-specific implementations of services.
         containerBuilder.RegisterType&lt;LoggingService&gt;()
                         .As&lt;ILoggingService&gt;()
                         .SingleInstance();
  
         containerBuilder.RegisterType&lt;SQLitePlatformService&gt;()
                         .As&lt;ISQLitePlatformService&gt;()
                         .SingleInstance();
  
         containerBuilder.RegisterType&lt;DiskStorageService&gt;()
                         .As&lt;IDiskStorageService&gt;()
                         .SingleInstance();
  
         ...
  
         containerBuilder.RegisterType&lt;Facade&gt;()
                         .As&lt;IFacade&gt;();
  
         //  Auto-magically resolves the IFacade implementation.
         var facadeContainer = containerBuilder.Build();
         var facadeLifetimeScope = m_facadeContainer.BeginLifetimeScope();
  
         return facadeLifetimeScope.Resolve&lt;IFacade&gt;();
     }
  }
  </code></pre>
  
  <p>I need to pass my <code>IFacade</code> instance around to the different <code>Page</code>s to reach my view-models. Here is an example of one of my pages:</p>
  
  <pre><code>internal sealed partial class SomePage
  {
      public SomePageViewModel ViewModel { get; }
  
      public SomePage()
      {
          ViewModel = new SomePageViewModel(/* need an IFacade implementation here!! */);
  
          InitializeComponent();
      }
  
      protected override void OnNavigatedTo(NavigationEventArgs e)
      {
          ViewModel.LoadAsync();
  
          base.OnNavigatedTo(e);
      }
  }
  </code></pre>
  
  <p>UWP is responsible for the <code>Page</code>s instantiation so it limits my options. Here is how the navigation from one page to another is done in UWP. From the <code>App</code> instance:</p>
  
  <pre><code>rootFrame.Navigate(typeof(MainPage), e.Arguments);
  </code></pre>
  
  <p>Or from a <code>Page</code> instance:</p>
  
  <pre><code>ContentFrame.Navigate(typeof(SomeOtherPage));
  </code></pre>
  
  <p><strong>Question</strong></p>
  
  <p>What would be the proper way to pass my <code>IFacade</code> instance around to the view-models (without doing anything hacky obviously)?</p>