title: What is the Best Way to Dynamically Create an MSMQ Listener?
body: <p>I was using Spring.NET to create a message listener at application startup.  I now need the ability to create 0-n listeners, some of which could be listening to different queues.  I will need to be able to create/destroy them at run-time.  What would be the best way to go about doing this?  My previous spring configuration was something like:</p>
  
  <pre><code>&lt;objects xmlns="http://www.springframework.net"&gt;
  
    &lt;object id='inputQueue' type='Spring.Messaging.Support.MessageQueueFactoryObject, Spring.Messaging'&gt;
      &lt;property name='Path' value='.\Private$\inputQueue'/&gt;
    &lt;/object&gt;
  
    &lt;!-- MSMQ Transaction Manager --&gt;
    &lt;object id="messageQueueTransactionManager" type="Spring.Messaging.Core.MessageQueueTransactionManager, Spring.Messaging"/&gt;
  
    &lt;!-- Message Listener Container that uses MSMQ transactional for receives --&gt;
    &lt;object id="transactionalMessageListenerContainer" type="Spring.Messaging.Listener.TransactionalMessageListenerContainer, Spring.Messaging"&gt;
      &lt;property name="MessageQueueObjectName" value="inputQueue"/&gt;
      &lt;property name="PlatformTransactionManager" ref="messageQueueTransactionManager"/&gt;
      &lt;property name="MaxConcurrentListeners" value="10"/&gt;
      &lt;property name="MessageListener" ref="messageListenerAdapter"/&gt;
    &lt;/object&gt;
  
    &lt;!-- Adapter to call a PONO as a messaging callback --&gt;
    &lt;object id="messageListenerAdapter" type="Spring.Messaging.Listener.MessageListenerAdapter, Spring.Messaging"&gt;
      &lt;property name="HandlerObject" ref="messageListener"/&gt;
    &lt;/object&gt;
  
    &lt;!-- The PONO class that you write --&gt;
    &lt;object id="messageListener" type="Com.MyCompany.Listener, Com.MyCompany"&gt;
      &lt;property name="Container" ref="transactionalMessageListenerContainer"/&gt;
    &lt;/object&gt;   
  
  &lt;/objects&gt;
  </code></pre>
  
  <p>Should I just programmatically do what this file is doing each time I need a new listener?  Should I not use Spring.NET's messaging framework for this?</p>