title: injecting viewmodel class without parameterless constructor in WPF with NInject
body: <p>I'm using NInject to resolve the dependency for my first WPF application.
  Following are my code snippets.</p>
  
  <p>My App.xaml.cs goes like.</p>
  
  <pre><code>public partial class App : Application
  {
      private IKernel container;
  
      protected override void OnStartup(StartupEventArgs e)
      {
          base.OnStartup(e);
          ConfigureContainer();
          ComposeObjects();
      }
  
      private void ComposeObjects()
      {
          Current.MainWindow = this.container.Get&lt;MainWindow&gt;();
      }
  
      private void ConfigureContainer()
      {
          this.container = new StandardKernel();
          container.Bind&lt;ISystemEvents&gt;().To&lt;MySystemEvents&gt;();
  
      }
  }
  </code></pre>
  
  <p>App.xaml goes like this.</p>
  
  <pre><code>&lt;Application x:Class="Tracker.App"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
      &lt;Application.Resources&gt;
  
      &lt;/Application.Resources&gt;
  &lt;/Application&gt;
  </code></pre>
  
  <p>MainWindow.xaml.</p>
  
  <pre><code>&lt;Window x:Class="Tracker.MainWindow"
          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
          xmlns:viewmodel="clr-namespace:Tracker.ViewModel"
          Title="MainWindow" Height="150" Width="350"&gt;
      &lt;Window.DataContext&gt;
          &lt;viewmodel:TrackerViewModel&gt;
          &lt;/viewmodel:TrackerViewModel&gt;
      &lt;/Window.DataContext&gt;
      &lt;Grid&gt;
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>MainWindow.xaml.cs</p>
  
  <pre><code>public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
      }
  }
  </code></pre>
  
  <p>and viewmodel</p>
  
  <pre><code>internal class TrackerViewModel : System.ComponentModel.INotifyPropertyChanged
  {
      public TrackerViewModel(ISystemEvents systemEvents)
      {
          systemEvents.SessionSwitch += SystemEvents_SessionSwitch;
      }
  
      private void SystemEvents_SessionSwitch(object sender, SessionSwitchEventArgs e)
      {
      }
  }
  </code></pre>
  
  <p>Now when I launch the application, I get an exception <code>An unhandled exception of type 'System.NullReferenceException' occurred in PresentationFramework.dll</code> in <code>InitializeComponent()</code> method. </p>
  
  <p>I know its because of the viewmodel class not have parameterless constructor. But I am not able to undestand why dependency injector is not able to resolve this? Am I doing something wrong?</p>
  
  <p>Any help would be greatly appreciated.</p>