0

I have to implement a model based access security on an existing system, to prevent users from loading/changing data from other users. So I created a couple of interfaces for that purpose and made model classes implement them. I have a base repository class which calls all the queries, so I can check those interfaces only in one place and everything will work. And it does, but I'm not sure if I broke the Future feature in the meanwhile.

So basically, the question is very simple, if I call this extension method after each Future() call, will it trigger the query immediately (breaking the purpose of future)? Does Where() or casting to interface force Future to execute immediately?

internal static IEnumerable<TX> ApplyRestrictions<TX>(this IEnumerable<TX> results, IUnitOfWork uow)
{
    if (typeof(IContextUser).IsAssignableFrom(typeof(TX)))
    {
        var currentUser = uow.UserRepository.FindCurrentUser();
        return results.Where(x => (x as IContextUser).User == currentUser);
    }
    if (typeof(IContextCompany).IsAssignableFrom(typeof(TX)))
    {
        var currentCompany = uow.CompanyRepository.FindCurrentCompany();
        return results.Where(x => (x as IContextCompany).Company == currentCompany);
    }

    return results;
}
ZolaKt
  • 4,683
  • 8
  • 43
  • 66

1 Answers1

0

Nevermind, I just tested it with Glimpse. It does NOT trigger an immediate query, which is great.

ZolaKt
  • 4,683
  • 8
  • 43
  • 66