public class PatientFinderProvider : IPatientFinderService {
public string Name => "My Extended Service";
// Add: Local references to static services
private IAdHocCacheService adhocCache;
private IPasswordHashingService hashingService;
// Constructor indicating services required
public PatientFinderProvider(IAdHocCacheService adHocCache, IPasswordHashingService hashingService)
this.adhocCache = adHocCache;
this.hashingService = hashingService;
public Patient FindPatient(string id) {
// Get the repository service
var repo = ApplicationServiceContext.Current.GetService<IRepositoryService<Patient>>();
// Check if repository was null
throw new InvalidOperationException("Couldn't find a valid Patient Repository");
// Check if the patient exists in the cache
var key = this.hashingService.ComputeHash(id);
var patient = this.adhocCache.Get<Patient>(key);
if(patient == null) // Load from DB
patient = repo.Find(p=>p.Identifiers.Any(i=>i.Value == id)).FirstOrDefault();
this.adhocCache.Add(key, patient);