Skip to content

Instantly share code, notes, and snippets.

@TWolverson
Created January 15, 2015 09:34
Show Gist options
  • Save TWolverson/3db1a7aee8731103679b to your computer and use it in GitHub Desktop.
Save TWolverson/3db1a7aee8731103679b to your computer and use it in GitHub Desktop.
public class ReferenceValuesService{
public ReferenceValuesService(Func<Context> contextFactory){
this.contextFactory = contextFactory;
this.referenceValues = new Lazy<IEnumerable<ReferenceValue>>(() => this.contextFactory().GetReferenceValues());
}
public IEnumerable<ReferenceValue> ReferenceValues(){
return this.referenceValues.Value;
}
private readonly Lazy<IEnumerable<ReferenceValue>> referenceValues;
}
public class Context : DbContext{
public virtual ObjectResult<ReferenceValue> GetReferenceValues(){
//Entity Framework cruft
}
}
// instantiate ReferenceValuesService as new ReferenceValuesService(() => new Context())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment