Created
January 20, 2011 00:38
-
-
Save mgroves/787189 to your computer and use it in GitHub Desktop.
lazy load 3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [LazyLoad] private IProductRepository _productRepository; | |
| [Serializable] | |
| public sealed class LazyLoadAttribute : LocationInterceptionAspect | |
| { | |
| public override void OnGetValue(LocationInterceptionArgs args) | |
| { | |
| args.ProceedGetValue(); // this actually fetches the field and populates the args.Value | |
| 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