Created
January 19, 2011 02:10
-
-
Save mgroves/785556 to your computer and use it in GitHub Desktop.
lazy load 4
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 | |
| { | |
| private Type _type; | |
| public override bool CompileTimeValidate(PostSharp.Reflection.LocationInfo locationInfo) | |
| { | |
| _type = DependencyMap.GetConcreteType(locationInfo.LocationType); | |
| if(_type == null) | |
| { | |
| Message.Write(SeverityType.Error, "002", "A concrete type was not found"); | |
| return false; | |
| } | |
| return true; | |
| } | |
| public override void OnGetValue(LocationInterceptionArgs args) | |
| { | |
| args.ProceedGetValue(); | |
| if (args.Value == null) | |
| { | |
| form.LogLogLogListBox.Items.Add("Instantiating UserService"); | |
| args.SetNewValue(Activator.CreateInstance(_type)); | |
| } | |
| else | |
| { | |
| form.LogLogLogListBox.Items.Add("Using a UserService that has already been created"); | |
| } | |
| args.ProceedGetValue(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment