title: Prism - EventAggregator.GetEvent<>.Subscribe() - Using Generics & Contraints
body: <p>I am having an issue subscribing to events with the event Aggregator that comes as part of the prism framework.</p>
  
  <p>If I use something such as</p>
  
  <pre><code>eventAggregator.GetEvent&lt;string&gt;().Subscribe(MyMethod)
  </code></pre>
  
  <p>then it all works ok, my method fires when an event has been published.</p>
  
  <p>However, when moving to a more complex object other than I string I run into problems.</p>
  
  <p>I have a bunch of classes that all derive from an Interface (IRequest) for example</p>
  
  <p>I have my event class setup as follows</p>
  
  <pre><code>public class MyEvent&lt;TRequest&gt; : PubSubEvent&lt;MyClass&lt;TRequest&gt;&gt; where TRequest : IRequest {}
  </code></pre>
  
  <p>I have a generic class (MyClass) that uses an object of IRequest inside it - again, all seems to work ok at this point.</p>
  
  <p>Now, lets say I publish an event of MyClass that uses the object Profile inside it:</p>
  
  <pre><code>eventAggregator.GetEvent&lt;MyEvent&lt;Profile&gt;&gt;().Publish(myProfileObject);
  </code></pre>
  
  <p>In my subscription I would like a method that can catch all events of MyEvent - Irrelevant of whether T is Profile or some other object that derives from IRequest - this is where I seem to be having problems.</p>
  
  <p>In the following examples, the first works, but the second doesn't - I would ideally like to use something similar to the second.</p>
  
  <pre><code>eventAggregator.GetEvent&lt;MyEvent&lt;Profile&gt;&gt;().Subscribe(test1);
  void test1 (MyClass&lt;Profile&gt; obj)
  {
    //Some stuff here
  }
  
  eventAggregator.GetEvent&lt;MyEvent&lt;IRequest&gt;&gt;().Subscribe(test2);
  void test2&lt;T&gt;(MyClass&lt;T&gt; obj) where T : IRequest
  {
    //never gets called
  }
  </code></pre>
  
  <p>My assumption is that because Profile derives from IRequest then it should work???  But it doesn't!!</p>
  
  <p>Any help would be appreciated.</p>
  
  <p><strong>UPDATE</strong><br>
  If I use the following, it does work, but would require me to create a separate subscription for each type of IRequest available - I'm looking to only have the one subscription.</p>
  
  <pre><code>eventAggregator.GetEvent&lt;MyEvent&lt;Profile&gt;&gt;().Subscribe(test2);
  eventAggregator.GetEvent&lt;MyEvent&lt;User&gt;&gt;().Subscribe(test2);
  </code></pre>