Beyond Dependency Injection: Listing 4.

The SelectHandler method.

public IHandler SelectHandler(string key,
  Type service,
  IHandler[] handlers)
{
  if (networkAvailable)
  {
  return handlers.Where(
  h => h.ComponentModel.Implementation == typeof (RestDataFeed))
  .FirstOrDefault();
  }

  return handlers.Where(
  h => h.ComponentModel.Implementation == typeof(LocalDataFeed))
  .FirstOrDefault();
}

About the Author

Patrick Steele is a senior .NET developer with Billhighway in Troy, Mich. A recognized expert on the Microsoft .NET Framework, he’s a former Microsoft MVP award winner and a presenter at conferences and user group meetings.