Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save mgroves/785518 to your computer and use it in GitHub Desktop.
lazy load 3
[LazyLoad] private IProductRepository _productRepository;
[Serializable]
public sealed class LazyLoadAttribute : LocationInterceptionAspect
{
public override void OnGetValue(LocationInterceptionArgs args)
{
args.ProceedGetValue();
if (args.Value == null)
{
var locationType = args.Location.LocationType;
var instantiation = ObjectFactory.GetInstance(locationType);
if (instantiation != null)
{
args.SetNewValue(instantiation);
}
}
args.ProceedGetValue();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment