Skip to content

Instantly share code, notes, and snippets.

@mgroves
Created January 19, 2011 01:30
Show Gist options
  • Select an option

  • Save mgroves/785516 to your computer and use it in GitHub Desktop.

Select an option

Save mgroves/785516 to your computer and use it in GitHub Desktop.
lazy loading 3
[Serializable]
public sealed class LazyLoadAttribute : LocationInterceptionAspect
{
public override void OnGetValue(LocationInterceptionArgs args)
{
var form = (ProductForm)args.Instance; // this form is only used here to write to a listbox for demonstration
args.ProceedGetValue();
if (args.Value == null)
{
form.LogListBox.Items.Add("Instantiating ProductService");
var locationType = args.Location.LocationType;
var instantiation = ObjectFactory.GetInstance(locationType);
if (instantiation != null)
{
args.SetNewValue(instantiation);
}
} else
{
form.LogListBox.Items.Add("Using a ProductService that has already been instantiated");
}
args.ProceedGetValue();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment