在我的项目中,Iám从MVC控制器调用我的代码库。 我的存储库具有使用Exchange Server,Echange Managed API的功能。
现在,我想在我的项目中实现依赖注入。
我无法弄清楚我的代码中必须修改哪些内容以通过依赖注入调用Repository
有人可以帮忙吗?
她的我的存储库:
public class ExchangeEws : IExchangeEws
{
public List<DateTime> GetAvaliableBookingDays(ExchangeService service, List<Advisor> advisors, DateTime startDate, DateTime endDate, int Num_Appt)
{
List<DateTime> avaliableBookingDays = new List<DateTime>();
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<Appointment> appointments = calendar.FindAppointments(cView);
if (appointments.Count() > 0)
{
avaliableBookingDays.AddRange((from appObj in appointments
where (appObj.AppointmentType == AppointmentType.Occurrence || appObj.AppointmentType == AppointmentType.Exception) && appObj.LegacyFreeBusyStatus == LegacyFreeBusyStatus.Free && appObj.Subject.ToLower().Contains("kwodkowdkowdow")
select appObj.Start).ToList());
}
}
List<DateTime> distinctDates = avaliableBookingDays
.GroupBy(day => day.Date)
.Select(g => g.First())
.ToList();
return distinctDates;
}
}
这是我的控制器:
public class HomeController : Controller
{
public ActionResult service()
{
List<Advisor> adv = new List<Advisor>() { 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();
}