title: Multiple navigation control through dependency injection
body: <p>My base content class. I used this class as a theme for my project. I do not know this info relevant or not. In here I create an abstract method that would overload the navigation method.</p>
  
  <pre><code>public abstract class BaseContentPage : ContentPage
  {
      public readonly BaseViewModel BaseViewModel;
  
      public BaseContentPage(BaseViewModel baseViewModel)
      {
          BaseViewModel = baseViewModel;
      }
  
      public abstract void Navigate(SelectedItemChangedEventArgs e);
  }
  </code></pre>
  
  <p>In my locator where I build the dependency Injection public class Locator. in this class mainly focus on adding this class to the container to make the all code loss coupling</p>
  
  <pre><code>    private readonly ContainerBuilder _builder;
  
      public Locator()
      {
          _builder = new ContainerBuilder();
          RegisterTypes();
          Container = _builder.Build();
      }
  
      public IContainer Container { get; set; }
  
      private void RegisterTypes()
      {
          _builder.RegisterType&lt;WardListService&gt;().As&lt;IWardListService&gt;();
          _builder.RegisterType&lt;WardListPageViewModel&gt;();
          _builder.RegisterType&lt;WardListPage&gt;();
  
          _builder.RegisterType&lt;PatientService&gt;().As&lt;IPatientService&gt;();
          _builder.RegisterType&lt;PatientListPageViewModel&gt;();
          _builder.RegisterType&lt;PatientListViewPage&gt;();
  
          _builder.RegisterType&lt;PatientDetailsPageViewModel&gt;();
          _builder.RegisterType&lt;PatientDetailsViewPage&gt;();   }
  </code></pre>
  
  <p>In my <strong>app.Xaml.Cs</strong> file</p>
  
  <pre><code> public App()
      {
          InitializeComponent();              
          Locator locator = new Locator();
          Container = locator.Container;
          MainPage = new NavigationPage(Container.Resolve&lt;WardListPage&gt;());
      }
  
      public static IContainer Container;
  </code></pre>
  
  <p>I used this method for navigation in my view code behind page</p>
  
  <pre><code>    public async override void Navigate(SelectedItemChangedEventArgs e)
      {
          PatientDetailsViewPage patientDetailsViewPage = App.Container.Resolve&lt;PatientDetailsViewPage&gt;();
          patientDetailsViewPage.BaseViewModel.SelectedPatient = e.SelectedItem as PatientViewModel;
          await Navigation.PushAsync(patientDetailsViewPage);
      }
  </code></pre>
  
  <p>This code is working perfectly but this only can navigate to one page.meaning as an example on one page we have two buttons that navigate to two different pages. I don't know how to implement this task using above navigate overloader. How to do it can anyone give suggestion to overcome the problem?. Also, I used autofac for dependency injection Thank you</p>