OperationContext
De RbacOperationContext is een cruciaal onderdeel van het RBAC (Role-Based Access Control) systeem. Deze context houdt belangrijke informatie bij tijdens RBAC-operaties en zorgt voor een consistente toestand tussen verschillende componenten.
Doel en Functie
De operatiecontext fungeert als een gedeelde toestandscontainer die:
public interface IRbacOperationContext
{
Guid CurrentRunId { get; }
Guid VersionId { get; }
bool IsRollback { get; }
bool IsAuditing { get; }
void SetCurrentIds(Guid runId, Guid versionId);
void SetRollback(bool isRollback);
void SetAuditing(bool isAuditing);
}
internal sealed class RbacOperationContext : IRbacOperationContext
{
public Guid CurrentRunId { get; private set; } = Guid.NewGuid();
public Guid VersionId { get; private set; }
public bool IsRollback { get; private set; }
public bool IsAuditing { get; private set; }
public void SetCurrentIds(Guid runId, Guid versionId)
{
CurrentRunId = runId;
VersionId = versionId;
}
public void SetRollback(bool isRollback) => IsRollback = isRollback;
public void SetAuditing(bool isAuditing) => IsAuditing = isAuditing;
}
operationContext.SetRollback(notification.IsRollback);
operationContext.SetCurrentIds(notification.RunId, rbac.ActiveVersion!.Value);
Deze context houdt bij:
Het huidige RunId van de operatie
De versie-identifier (VersionId)
Of een operatie deel uitmaakt van een rollback-proces
Andere toestanden die nodig zijn over de verschillende function calls heen
Gebruik in Handlers De context wordt gebruikt in verschillende handlers, zoals de RbacManagementActivatedHandler:
public class RbacManagementActivatedHandler(
[FromKeyedServices(KeyedServices.LogDecorator)]
IRbacService rbacService,
IRbacOperationContext operationContext,
IUnitOfWork unitOfWork,
IPublisher publisher,
ILogger<RbacManagementActivatedHandler> logger)
Rollback Ondersteuning Bij fouten tijdens RBAC-activering wordt de context gebruikt om rollback-informatie door te geven:
if (initiateRollback)
{
var auditLog = RbacAuditLog.CreateRollbackLog(notification.RunId, notification.VersionId);
var rollbackEvent = new RbacRollbackEvent() {TenantId = notification.TenantId, RunId = notification.RunId, VersionId = notification.VersionId};
await rbacService.InitiateRbacRollback(rollbackEvent, auditLog).ConfigureAwait(false);
}
Deze rollback-functionaliteit zorgt ervoor dat het systeem in een consistente toestand blijft, zelfs wanneer er fouten optreden tijdens RBAC-operaties.
Last modified: 23 March 2026