I have a list of permissions defined like this:
private List<PermissionItem> permissionItems;
private ReadOnlyCollection<PermissionItem> permissionItemsReadOnly;
This list is retrieved from a web service via a background thread. The read only version is filled from the List version.
I expose this list to the rest of my (rather large) application like this:
public IQueryable<PermissionItem> PermissionItems
{
get
{
// Make sure that the permissions have returned.
// If they have not then we need to wait for that to happen.
if (!doneLoadingPermissions.WaitOne(10000))
throw new ApplicationException("Could not load permissions");
return permissionItemsReadOnly.AsQueryable();
}
}
This is all well and good. The user can ask for permissions and get them once they have loaded.
But if I have code like this in a constructor (in a different class):
ThisClassInstanceOfThePermisssions = SecurityStuff.PermissionItems;
Then I am fairly sure that will block until the permissions return. But it does not need to block until the permissions are actually used.
I have read that IQueryable is "Lazy Loading". (I have used this feature in my Entity Framework code.)
Is there a way I could change this to allow references to my IQueryable at any time, and only block when the data is actually used?
Note: This is a "nice to have" feature. Actually loading the permissions does not take too long. So if this is a "roll your own" query/expression stuff, then I will probably pass. But I am curious what it takes to make it work.