Created
September 9, 2022 14:41
-
-
Save mrpmorris/6ed1caf53bf6836b960f516772cb6152 to your computer and use it in GitHub Desktop.
IdentityService.cs
This file contains 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
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