title: Dependency Injection in WebAPI with Castle Windsor
body: <p>I want to implement Dependency Injection in WebApi application using Castle Windsor. I have following sample code -</p>
  
  <p><strong>Interface -</strong></p>
  
  <pre><code>public interface IWatch
  {
      {
          DateTime GetTime();
      }
  }
  </code></pre>
  
  <p>Following <strong>Watch class</strong> implements <strong>IWatch</strong> Interface -</p>
  
  <pre><code>public class Watch:IWatch
  {
          public DateTime GetTime()
          {
              return DateTime.Now;
          }
  }
  </code></pre>
  
  <p>WebApi Controller - <strong>WatchController</strong> as below -</p>
  
  <pre><code>public class WatchController : ApiController
  {
          private readonly IWatch _watch;
  
          public WatchController()
          {
              _watch = new Watch();
          }
  
          //http://localhost:48036/api/Watch
          public string Get()
          {
              var message = string.Format("The current time on the server is: {0}", _watch.GetTime());
              return message;
          }
  }
  </code></pre>
  
  <p>Currently I am initiating IWatch object with Watch in WatchController constructor. I want to remove dependency of initializing IWatch inside constructor using Windsor Castle dependency injection principle.</p>
  
  <p>Can anybody provide me the steps to implement dependency injection in this case of WebApi? Thanks in advance!</p>