title: Avoiding circular references for 2-way communication between projects
body: <p>I'm in the process of building an open-source tiling window manager applications similar to i3wm/bspwm. <a href="https://preview.redd.it/edgdl9omg5n21.png?width=960&amp;crop=smart&amp;auto=webp&amp;s=1b4ef7a63efe9fdd99c2f62f3605d9fa743db17d" rel="nofollow noreferrer">Would hopefully look something like this, but for Windows</a>. There's a little bar at the top of the screen that shows your "workspaces" and you can click on a workspace to show its windows.</p>
  
  <p>At the moment, there's 3 projects in my solution: Bar, Window Manager and Common. The Window Manager project holds state of workspaces etc. and has commands that Bar is supposed to trigger. Common just holds infrastructure shared between the 2 projects like a <code>CommandBus</code> for facilitating communication between projects.</p>
  
  <p>The Bar project consists of something like this:</p>
  
  <pre><code>public LaunchBar()
  {
      // Launch WPF app.
      InitializeComponent();
  
      // Bind current workspaces to template.
      workspaces.ItemsSource = workspaceRepository.GetWorkspaces(); // workspaceRepository exists in Window Manager project
  }
  
  private void OnWorkspaceClick()
  {
      commandBus.Invoke(new ChangeWorkspaceCommand()); // ChangeWorkspaceCommand exists in Window Manager project
  }
  </code></pre>
  
  <p>The idea is that <code>LaunchBar</code> is called programmatically within the Window Manager project when a new monitor is detected. However, this results in a circular reference between the two projects.</p>
  
  <p>How can I go about structuring this project to avoid circular references? Fairly gosh darn stuck here.</p>