title: Centralizing actions of a program
body: <p>I have a program that needs to perform some actions from various forms. I want to keep the actions in a centralized space. Each action has its own class that is derived from a interface. </p>
  
  <p>Each action is only instantiated once, but is used on various places, like contextmenu, ribbon, toolbar and so on. </p>
  
  <p>I have the following code working, and I want to get rid of the typeof in when making a list. I want to have strong typing, no reflection and the possibility to refactor.</p>
  
  <p>Can this be done more efficient?</p>
  
  <pre><code>class Program
      {
          static void Main(string[] args)
          {
              ActionManager actionManager = new ActionManager();
  
              List&lt;SomeInterface&gt; listA = actionManager.CreateList(typeof(Do_A), typeof(Do_B));
              List&lt;SomeInterface&gt; listB = actionManager.CreateList(typeof(Do_A), typeof(Do_B));
          }
      }
  
      public class ActionManager
      {
          private Dictionary&lt;Type, SomeInterface&gt; instantiatedActions = new Dictionary&lt;Type, SomeInterface&gt;();
  
          public List&lt;SomeInterface&gt; CreateList(params Type[] actions)
          {
              List&lt;SomeInterface&gt; theList = new List&lt;SomeInterface&gt;();
  
              foreach (Type type in actions)
              {
                  if(!instantiatedActions.ContainsKey(type))
                  {
                      instantiatedActions.Add(type, (SomeInterface)Activator.CreateInstance(type));
                  }
                  theList.Add(instantiatedActions[type]);
              }
  
              return theList;
          }
      }
  
      public interface SomeInterface
      {
      }
  
      public class Do_A : SomeInterface
      {
      }
  
      public class Do_B : SomeInterface
      {
      }
  
      public class Do_C : SomeInterface
      {
      }
  </code></pre>