title: Why my Subscribe method is not called when using Prism EventAggregator?
body: <p>I am learning Prism. Few hours already I am facing a problem, when subscribing to the event, the subscription method is not called. I am using <strong>Prism</strong> and <strong>Autofac</strong>.</p>
  
  <p>In the simplified example below, in <strong>MainViewModel</strong> <code>Publish("dupa");</code> event is called in the <code>ctor</code>. And on button click <strong>UpdateWindow</strong> is opened. In backend of the window is created instance of <strong>UpdateViewModel</strong>.</p>
  
  <p>Inside of <strong>update VM</strong> <code>ctor</code> is ran, but after <code>Subscribe(UpdateName);</code> the <strong>UpdateName</strong> is not executed, because of some reason that I do not understand.</p>
  
  <p>Complete code:</p>
  
  <pre><code>public class MainViewModel : ViewModelBase
      {
          private IEventAggregator _eventAggregator;
          public MainViewModel(IEventAggregator eventAggregator)
          {
              _eventAggregator = eventAggregator; //Prism
  
              _eventAggregator.GetEvent&lt;UpdateNameEvent&gt;().Publish("dupa");
  
              OnOpenCommand = new DelegateCommand(OnOpenWin);
          }
  
          public void OnOpenWin(object obj)
          {
              UpdateWindow win = new UpdateWindow();
              win.Show();
          }
  
          public ICommand OnOpenCommand { get; private set; }
      }
  
  
  public class UpdateViewModel : ViewModelBase
      {
          private IEventAggregator _eventAggregator;
  
          public UpdateViewModel(IEventAggregator eventAggregator)
          {
              _eventAggregator = eventAggregator; //Prism
              _eventAggregator.GetEvent&lt;UpdateNameEvent&gt;().Subscribe(UpdateName);
          }
  
          private void UpdateName(string name)
          {
              this.Name = name; //is not called at all
          }
  
          private string _name;
          public string Name
          {
              get
              {
                  return _name;
              }
              set
              {
                  _name = value;
                  OnPropertyChanged();
              }
          }
      }
  
  
  public partial class UpdateWindow : Window
      {
          public UpdateWindow()
          {
              var bootStrapper = new BootStrapper();
              var container = bootStrapper.BootStrap();
              UpdateViewModel vm = container.Resolve&lt;UpdateViewModel&gt;();
              InitializeComponent();
              DataContext = vm;
          }
      }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>After investigating, I notied, that when subscribing to the events like this, it works fine:</p>
  
  <p><code>Utility.EventAggregator.GetEvent&lt;UpdateNameEvent&gt;().Subscribe(UpdateName);</code></p>
  
  <p>When subscribing with used injected <strong>eventAggregator</strong>, it does not work:</p>
  
  <p><code>_eventAggregator.GetEvent&lt;UpdateNameEvent&gt;().Subscribe(UpdateName);</code></p>
  
  <p>And <strong>EventAggregator</strong> is registered by <strong>Autofac</strong> as follows:</p>
  
  <pre><code>builder.RegisterType&lt;EventAggregator&gt;()
          .As&lt;IEventAggregator&gt;().SingleInstance();
  </code></pre>
  
  <p>I do not understand why this dependency does not work?</p>