Created
January 19, 2011 01:30
-
-
Save mgroves/785516 to your computer and use it in GitHub Desktop.
lazy loading 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
| [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