Skip to content

Instantly share code, notes, and snippets.

@mrpmorris
Created September 9, 2022 14:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrpmorris/6ed1caf53bf6836b960f516772cb6152 to your computer and use it in GitHub Desktop.
Save mrpmorris/6ed1caf53bf6836b960f516772cb6152 to your computer and use it in GitHub Desktop.
IdentityService.cs
internal class IdentityService : IIdentityService
{
// Other properties like the current user etc
public bool IsRunningWithElevatedPrivileges => ElevatedPrivilegeCount > 0;
private volatile int ElevatedPrivilegeCount;
public IDisposable ExecuteWithElevatedPrivileges()
{
Interlocked.Increment(ref ElevatedPrivilegeCount);
return new DisposableCallback(() => Interlocked.Decrement(ref ElevatedPrivilegeCount));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment