title: C#: How to resolve this circular dependency?
body: <p>I have a circular dependency in my code, and I'm not sure how to resolve it. </p>
  
  <p>I am developing a game. A NPC has three components, responsible for thinking, sensing, and acting. These components need access to the NPC controller to get access to its model, but the controller needs these components to do anything. Thus, both take each other as arguments in their constructors.</p>
  
  <pre><code>ISenseNPC sense = new DefaultSenseNPC(controller, worldQueryEngine);
  IThinkNPC think = new DefaultThinkNPC(sense);
  IActNPC act = new DefaultActNPC(combatEngine, sense, controller);
  controller = new ControllerNPC(act, think);
  </code></pre>
  
  <p>(The above example has the parameter simplified a bit.)</p>
  
  <p>Without <code>act</code> and <code>think</code>, <code>controller</code> can't do anything, so I don't want to allow it to be initialized without them. The reverse is basically true as well. What should I do?</p>
  
  <p><code>ControllerNPC</code> using <code>think</code> and <code>act</code> to update its state in the world:</p>
  
  <pre><code>public class ControllerNPC {
     // ...
             public override void Update(long tick)
          {
              // ...
              act.UpdateFromBehavior(CurrentBehavior, tick);
  
              CurrentBehavior = think.TransitionState(CurrentBehavior, tick);
          }
     // ...
  
  }
  </code></pre>
  
  <p><code>DefaultSenseNPC</code> using <code>controller</code> to determine if it's colliding with anything:</p>
  
  <pre><code> public class DefaultSenseNPC {
         // ...
              public bool IsCollidingWithTarget()
              {
                  return worldQuery.IsColliding(controller, model.Target);
              }
         // ...
      }
  </code></pre>