title: Injecting dependency in C#
body: <p>I have an Airport class where Plane objects can take off and land, depending on the weather. If it's stormy, they can't take off/land and if it's sunny they can. I have the following Airport constructor: </p>
  
  <pre class="lang-cs prettyprint-override"><code>public string AirportName { get; set; }
  public List&lt;Plane&gt; planes;
  
  public Airport(string airportName)
  {
      planes = new List&lt;Plane&gt;();
      AirportName = airportName;
      Weather weather = new Weather(); 
  }
  </code></pre>
  
  <p>I have a Weather class that randomises the weather: </p>
  
  <pre class="lang-cs prettyprint-override"><code>public class Weather
  {
      public Weather()
      {
      }
  
      public string Forecast()
      {
          Random random = new Random();
          var weather = random.Next(1, 11);
          if (weather == 1 || weather == 2)
          {
              return "stormy";
          }
          else
          {
              return "sunny";
          }
      }
  }
  </code></pre>
  
  <p>This is how I use the airport in Main: </p>
  
  <pre class="lang-cs prettyprint-override"><code>static void Main()
  {
      var gatwick = new Airport("London Gatwick");
  }
  </code></pre>
  
  <p>As the Weather information is provided by a separate class I would like to  inject it into Airport as a dependency. However, I am struggling to do this in C# as I'm really new to the language. Would it be something such as: <code>public Airport(string airportName, Weather weather)</code>?</p>
  
  <p>Would be really grateful if someone could help me understand how to inject as a dependency and how to then call this in Main. Thank you!</p>