title: Implement Dependency injection in MVC (Webservices)
body: <p>In my project, Iám calling my Code Repository from MVC Controllers.
  My Repository  have function to work with Exchange Server, Echange Managed API.</p>
  
  <p>Now, i want to implement dependency injection in my project.</p>
  
  <p>I can not figure out what in my code must be modified to call Repository with dependency injection</p>
  
  <p>Can anybody help ?</p>
  
  <p>Her my Repository:</p>
  
  <pre><code>  public class ExchangeEws : IExchangeEws
  {
                  public List&lt;DateTime&gt; GetAvaliableBookingDays(ExchangeService service, List&lt;Advisor&gt; advisors, DateTime startDate, DateTime endDate, int Num_Appt)
              {
  
                  List&lt;DateTime&gt; avaliableBookingDays = new List&lt;DateTime&gt;();
  
  
                  foreach (Advisor adObj in advisors)
                  {
                      // Get user's calendar folder 
                      CalendarFolder calendar = CalendarFolder.Bind(service, new FolderId(WellKnownFolderName.Calendar, adObj.EmailAddress), new PropertySet());
  
                      //  appointments to retrieve.(CalendarView return recurring appointment)
                      CalendarView cView = new CalendarView(startDate, endDate, Num_Appt);
  
                      //  def properties to get returned
                      cView.PropertySet = new PropertySet(AppointmentSchema.Start, AppointmentSchema.IsRecurring, AppointmentSchema.LegacyFreeBusyStatus, AppointmentSchema.Subject, AppointmentSchema.AppointmentType);
  
  
                      FindItemsResults&lt;Appointment&gt; appointments = calendar.FindAppointments(cView);
  
                      if (appointments.Count() &gt; 0)
                      {
                          avaliableBookingDays.AddRange((from appObj in appointments
                                                         where (appObj.AppointmentType == AppointmentType.Occurrence || appObj.AppointmentType == AppointmentType.Exception) &amp;&amp; appObj.LegacyFreeBusyStatus == LegacyFreeBusyStatus.Free &amp;&amp; appObj.Subject.ToLower().Contains("kwodkowdkowdow")
                                                         select appObj.Start).ToList());
                      }
                  }
  
  
                  List&lt;DateTime&gt; distinctDates = avaliableBookingDays
                                                 .GroupBy(day =&gt; day.Date)
                                                 .Select(g =&gt; g.First())
                                                 .ToList();
  
                  return distinctDates;
              }
      }
  </code></pre>
  
  <p>Here my Controller:</p>
  
  <pre><code>         public class HomeController : Controller
          {        
            public ActionResult service()
              {
   List&lt;Advisor&gt; adv = new List&lt;Advisor&gt;() { new Advisor { ID = 1, Location = "London", EmailAddress = "dwded@dd.dk", Name = "Loppe" } };
  
                  ExchangeService service= ExchangeEws.GetExchangeConnection("xxxx@jj.com", password);
  
                  ExchangeEws x = new ExchangeEws();
  
  
  
                   x.GetAvaliableBookingDays(service, adv, DateTime.Now, DateTime.Now.AddDays(45), 20);
  
  
                  return View();
              }
  </code></pre>