fix(centralui): no-tracking default on the circuit DbContext; mutations on their own scope (UI-1, WP5 task 5.1)
The circuit-lifetime ScadaBridgeDbContext tracked every entity a page ever loaded, so a reload returned the first-loaded instance and never saw changes made in another scope (Move to Site, Topology area renames, a template script edited by the CLI/import - which a later save then silently reverted). - CircuitDbContextTrackingHandler (CircuitHandler, registered by AddCentralUI) sets QueryTrackingBehavior.NoTracking on the circuit scope's context only, when the circuit host is built (before any component). Management-actor, command-transaction, HTTP-request and hosted-service scopes keep TrackAll. - Every remaining page mutation that ran a load-modify-save service on the circuit context now runs it via ScopeFactory.InNewScopeAsync (fresh tracking context): TemplateEdit (17 TemplateService calls), Templates (5 TemplateService + 5 TemplateFolderService), TemplateCreate, SharedScripts, SharedScriptForm, TransportImport.ApplyAsync. (Sites/Topology moved in 5.2.) - Design doc: Component-CentralUI.md 'Circuit DbContext lifetime'. Tests: CircuitDbContextTrackingTests - handler scoping + registration, the three finding scenarios against a real SQLite context (moved connection also asserts the pre-fix staleness without the handler), and a source-scan guard that fails on any mutating call through a circuit-injected load-modify-save service.
This commit is contained in:
@@ -362,12 +362,20 @@ Per-leaf alarm rendering (leaf nodes are individual conditions for native alarms
|
||||
|
||||
### Configuration mutations and live circuit authority (2026-09-09)
|
||||
|
||||
Page configuration handlers use `ConfigurationCommandService` and the guarded management command boundary. Database changes and their scrubbed audit entries commit in one transaction, including generated entity IDs. Existing instance service operations execute through the same transaction seam and retain their domain validation and audit ownership. Circuit read tracking is cleared after a separate transaction scope changes configuration.
|
||||
Page configuration handlers use `ConfigurationCommandService` and the guarded management command boundary. Database changes and their scrubbed audit entries commit in one transaction, including generated entity IDs. Existing instance service operations execute through the same transaction seam and retain their domain validation and audit ownership. Circuit read tracking is cleared after a separate transaction scope changes configuration (a no-op since the circuit context stopped tracking — see below).
|
||||
|
||||
Cookie circuits retain their initial principal without retaining `HttpContext`; authoritative reads re-map stored directory groups against current grants. Mutation handlers recheck role and persisted target site immediately before dispatch. Passive session pings do not count as user activity. Trusted browser input posts an antiforgery-protected activity signal; the server activity tracker also makes it visible to the existing circuit.
|
||||
|
||||
The explicit server-configured development auto-login mode preserves its synthetic all-role principal. It uses the Cookies scheme but has no LDAP group claims; it must not enter directory re-mapping. This exception follows validated `AuthDisableLoginOptions`, never a caller-supplied claim.
|
||||
|
||||
### Circuit DbContext lifetime (code review 2026-12-02, UI-1/2/3/8)
|
||||
|
||||
In Blazor Server one DI scope — and so one scoped `ScadaBridgeDbContext` — lives for the whole circuit. That context now reads with a **no-tracking default**: `CircuitDbContextTrackingHandler` (a `CircuitHandler`, resolved when the circuit host is built, before any component) sets `ChangeTracker.QueryTrackingBehavior = NoTracking` on the circuit scope's context only. Every reload therefore sees the database as it is, including changes made in another scope — a data connection moved through the management actor, an area renamed by another user, a template script edited by the CLI or a Transport import. Contexts in every other scope (management-actor commands, the configuration command transaction, HTTP request scopes, hosted services, singleton actors) keep EF's tracking default.
|
||||
|
||||
No page mutates configuration on the circuit's context. Writes go through `ConfigurationCommandService` (its own transaction scope), the `ManagementActor`, or `ScopedServiceExtensions.InNewScopeAsync`, which resolves the load-modify-save service (`TemplateService`, `TemplateFolderService`, `SharedScriptService`, `DeploymentService`, `ArtifactDeploymentService`, `IBundleImporter.ApplyAsync`) from a fresh scope with an empty tracking context and disposes it when the action ends. A source-scan test (`CircuitDbContextTrackingTests`) fails the build if a page calls a mutating method on a circuit-injected instance of one of those services. Adding-only writes on the circuit context (an audit row, a bundle-unlock attempt) are unaffected by the tracking default.
|
||||
|
||||
Long or concurrent page work also runs on its own scope, so it can neither collide with another query on the circuit context ("A second operation was started on this context instance") nor die with the circuit: each Deployments-page load flight, the Sites page's **Deploy Artifacts** (per site and to all sites, whose record, audit rows and revision stamp are written after the site fan-out), and Topology's **Diff**, **Enable**, **Disable** and **Delete** (alongside the existing Deploy / Deploy all / staleness checks).
|
||||
|
||||
### Isolated Test Run workers
|
||||
|
||||
Test Run executes in a disposable `CentralUI.SandboxWorker` process. A process-wide admission gate permits at most four workers. Queueing, compilation, execution and gateway calls consume the requested deadline (1–10 seconds); cancellation kills the process tree and capacity is released only after confirmed exit. Console capture retains at most 32,000 characters with an explicit truncation marker; return JSON is limited to 32,000 bytes. Private IPC frames are limited to 1 MiB and stderr is drained without accumulation. Each worker has a 512 MiB managed-heap ceiling. The worker is a resource/lifetime boundary; the semantic script trust policy still gates compilation.
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
@page "/design/shared-scripts/create"
|
||||
@page "/design/shared-scripts/{Id:int}/edit"
|
||||
@using ZB.MOM.WW.ScadaBridge.CentralUI.Services
|
||||
@using Microsoft.Extensions.DependencyInjection
|
||||
@inject IServiceScopeFactory ScopeFactory
|
||||
@using ZB.MOM.WW.ScadaBridge.Security
|
||||
@using ZB.MOM.WW.ScadaBridge.Commons.Entities.Scripts
|
||||
@using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories
|
||||
@@ -278,8 +281,8 @@
|
||||
if (Id.HasValue)
|
||||
{
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await SharedScriptService.UpdateSharedScriptAsync(
|
||||
Id.Value, _formCode, _formParameters?.Trim(), _formReturn?.Trim(), user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((SharedScriptService svc) => svc.UpdateSharedScriptAsync(
|
||||
Id.Value, _formCode, _formParameters?.Trim(), _formReturn?.Trim(), user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
NavigationManager.NavigateTo("/design/shared-scripts");
|
||||
@@ -292,8 +295,8 @@
|
||||
else
|
||||
{
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await SharedScriptService.CreateSharedScriptAsync(
|
||||
_formName.Trim(), _formCode, _formParameters?.Trim(), _formReturn?.Trim(), user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((SharedScriptService svc) => svc.CreateSharedScriptAsync(
|
||||
_formName.Trim(), _formCode, _formParameters?.Trim(), _formReturn?.Trim(), user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
NavigationManager.NavigateTo("/design/shared-scripts");
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
@page "/design/shared-scripts"
|
||||
@using ZB.MOM.WW.ScadaBridge.CentralUI.Services
|
||||
@using Microsoft.Extensions.DependencyInjection
|
||||
@inject IServiceScopeFactory ScopeFactory
|
||||
@using ZB.MOM.WW.ScadaBridge.Security
|
||||
@using ZB.MOM.WW.ScadaBridge.Commons.Entities.Scripts
|
||||
@using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories
|
||||
@@ -151,7 +154,7 @@
|
||||
try
|
||||
{
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await SharedScriptService.DeleteSharedScriptAsync(script.Id, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((SharedScriptService svc) => svc.DeleteSharedScriptAsync(script.Id, user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
_toast.ShowSuccess($"Script '{script.Name}' deleted.");
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
@page "/design/templates/create"
|
||||
@using Microsoft.Extensions.DependencyInjection
|
||||
@inject IServiceScopeFactory ScopeFactory
|
||||
@using ZB.MOM.WW.ScadaBridge.CentralUI.Services
|
||||
@using ZB.MOM.WW.ScadaBridge.Security
|
||||
@using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates
|
||||
@@ -6,7 +8,6 @@
|
||||
@using ZB.MOM.WW.ScadaBridge.TemplateEngine
|
||||
@attribute [Authorize(Policy = AuthorizationPolicies.RequireDesign)]
|
||||
@inject ITemplateEngineRepository TemplateEngineRepository
|
||||
@inject TemplateService TemplateService
|
||||
@inject AuthenticationStateProvider AuthStateProvider
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
@@ -95,10 +96,10 @@
|
||||
try
|
||||
{
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await TemplateService.CreateTemplateAsync(
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.CreateTemplateAsync(
|
||||
_createName.Trim(), _createDescription?.Trim(),
|
||||
_createParentId == 0 ? null : _createParentId, user,
|
||||
folderId: FolderId);
|
||||
folderId: FolderId));
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
@using ZB.MOM.WW.ScadaBridge.Commons.Messages.Management
|
||||
@inject IServiceProvider MutationServices
|
||||
@page "/design/templates/{Id:int}"
|
||||
@using Microsoft.Extensions.DependencyInjection
|
||||
@inject IServiceScopeFactory ScopeFactory
|
||||
@using ZB.MOM.WW.ScadaBridge.Security
|
||||
@using ZB.MOM.WW.ScadaBridge.Commons.Entities.Instances
|
||||
@using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates
|
||||
@@ -569,7 +571,7 @@
|
||||
try
|
||||
{
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await TemplateService.DeleteTemplateAsync(_selectedTemplate.Id, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.DeleteTemplateAsync(_selectedTemplate.Id, user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
_toast.ShowSuccess($"Template '{_selectedTemplate.Name}' deleted.");
|
||||
@@ -592,9 +594,9 @@
|
||||
try
|
||||
{
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await TemplateService.UpdateTemplateAsync(
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.UpdateTemplateAsync(
|
||||
_selectedTemplate.Id, _editName.Trim(), _editDescription?.Trim(),
|
||||
_editParentId == 0 ? null : _editParentId, user);
|
||||
_editParentId == 0 ? null : _editParentId, user));
|
||||
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
@@ -818,7 +820,7 @@
|
||||
IsInherited = attr.IsInherited,
|
||||
LockedInDerived = newValue,
|
||||
};
|
||||
var result = await TemplateService.UpdateAttributeAsync(attr.Id, proposed, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.UpdateAttributeAsync(attr.Id, proposed, user));
|
||||
if (result.IsSuccess) { attr.LockedInDerived = newValue; _toast.ShowSuccess("Lock-in-derived updated."); }
|
||||
else _toast.ShowError(result.Error);
|
||||
}
|
||||
@@ -841,7 +843,7 @@
|
||||
IsInherited = false,
|
||||
LockedInDerived = false,
|
||||
};
|
||||
var result = await TemplateService.UpdateAttributeAsync(attr.Id, proposed, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.UpdateAttributeAsync(attr.Id, proposed, user));
|
||||
if (result.IsSuccess) { _toast.ShowSuccess($"Override saved for '{attr.Name}'."); await LoadAsync(); }
|
||||
else _toast.ShowError(result.Error);
|
||||
}
|
||||
@@ -864,7 +866,7 @@
|
||||
IsInherited = true,
|
||||
LockedInDerived = false,
|
||||
};
|
||||
var result = await TemplateService.UpdateAttributeAsync(attr.Id, proposed, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.UpdateAttributeAsync(attr.Id, proposed, user));
|
||||
if (result.IsSuccess) { _toast.ShowSuccess($"'{attr.Name}' reverted to base."); await LoadAsync(); }
|
||||
else _toast.ShowError(result.Error);
|
||||
}
|
||||
@@ -882,7 +884,7 @@
|
||||
try
|
||||
{
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await TemplateService.ResyncInheritedMembersAsync(Id, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.ResyncInheritedMembersAsync(Id, user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
var r = result.Value;
|
||||
@@ -1284,7 +1286,7 @@
|
||||
IsInherited = script.IsInherited,
|
||||
LockedInDerived = newValue,
|
||||
};
|
||||
var result = await TemplateService.UpdateScriptAsync(script.Id, proposed, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.UpdateScriptAsync(script.Id, proposed, user));
|
||||
if (result.IsSuccess) { script.LockedInDerived = newValue; _toast.ShowSuccess("Lock-in-derived updated."); }
|
||||
else _toast.ShowError(result.Error);
|
||||
}
|
||||
@@ -1308,7 +1310,7 @@
|
||||
IsInherited = true,
|
||||
LockedInDerived = false,
|
||||
};
|
||||
var result = await TemplateService.UpdateScriptAsync(script.Id, proposed, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.UpdateScriptAsync(script.Id, proposed, user));
|
||||
if (result.IsSuccess) { _toast.ShowSuccess($"Script '{script.Name}' reverted to base."); await LoadAsync(); }
|
||||
else _toast.ShowError(result.Error);
|
||||
}
|
||||
@@ -1426,7 +1428,7 @@
|
||||
IsInherited = existing.IsInherited,
|
||||
LockedInDerived = existing.LockedInDerived,
|
||||
};
|
||||
var result = await TemplateService.UpdateAttributeAsync(id, proposed, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.UpdateAttributeAsync(id, proposed, user));
|
||||
if (!result.IsSuccess) return result.Error;
|
||||
|
||||
_toast.ShowSuccess($"Attribute '{existing.Name}' updated.");
|
||||
@@ -1442,7 +1444,7 @@
|
||||
DataSourceReference = draft.DataSourceRef?.Trim()
|
||||
};
|
||||
|
||||
var addResult = await TemplateService.AddAttributeAsync(_selectedTemplate.Id, attr, user);
|
||||
var addResult = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.AddAttributeAsync(_selectedTemplate.Id, attr, user));
|
||||
if (!addResult.IsSuccess) return addResult.Error;
|
||||
|
||||
_toast.ShowSuccess($"Attribute '{draft.Name}' added.");
|
||||
@@ -1454,7 +1456,7 @@
|
||||
var confirmed = await Dialog.ConfirmAsync("Delete Attribute", $"Delete attribute '{attr.Name}'?", danger: true);
|
||||
if (!confirmed) return;
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await TemplateService.DeleteAttributeAsync(attr.Id, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.DeleteAttributeAsync(attr.Id, user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
_toast.ShowSuccess($"Attribute '{attr.Name}' deleted.");
|
||||
@@ -1562,7 +1564,7 @@
|
||||
Description = existing.Description,
|
||||
OnTriggerScriptId = existing.OnTriggerScriptId,
|
||||
};
|
||||
var result = await TemplateService.UpdateAlarmAsync(id, proposed, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.UpdateAlarmAsync(id, proposed, user));
|
||||
if (!result.IsSuccess) return result.Error;
|
||||
|
||||
_toast.ShowSuccess($"Alarm '{existing.Name}' updated.");
|
||||
@@ -1578,7 +1580,7 @@
|
||||
IsMesReportable = draft.IsMesReportable
|
||||
};
|
||||
|
||||
var addResult = await TemplateService.AddAlarmAsync(_selectedTemplate.Id, alarm, user);
|
||||
var addResult = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.AddAlarmAsync(_selectedTemplate.Id, alarm, user));
|
||||
if (!addResult.IsSuccess) return addResult.Error;
|
||||
|
||||
_toast.ShowSuccess($"Alarm '{draft.Name}' added.");
|
||||
@@ -1590,7 +1592,7 @@
|
||||
var confirmed = await Dialog.ConfirmAsync("Delete Alarm", $"Delete alarm '{alarm.Name}'?", danger: true);
|
||||
if (!confirmed) return;
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await TemplateService.DeleteAlarmAsync(alarm.Id, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.DeleteAlarmAsync(alarm.Id, user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
_toast.ShowSuccess($"Alarm '{alarm.Name}' deleted.");
|
||||
@@ -1698,7 +1700,7 @@
|
||||
IsInherited = existing.IsInherited,
|
||||
LockedInDerived = existing.LockedInDerived,
|
||||
};
|
||||
var result = await TemplateService.UpdateScriptAsync(id, proposed, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.UpdateScriptAsync(id, proposed, user));
|
||||
if (!result.IsSuccess) return result.Error;
|
||||
|
||||
_toast.ShowSuccess($"Script '{existing.Name}' updated.");
|
||||
@@ -1716,7 +1718,7 @@
|
||||
ExecutionTimeoutSeconds = NormalizeExecutionTimeout(draft.ExecutionTimeoutSeconds)
|
||||
};
|
||||
|
||||
var addResult = await TemplateService.AddScriptAsync(_selectedTemplate.Id, script, user);
|
||||
var addResult = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.AddScriptAsync(_selectedTemplate.Id, script, user));
|
||||
if (!addResult.IsSuccess) return addResult.Error;
|
||||
|
||||
_toast.ShowSuccess($"Script '{draft.Name}' added.");
|
||||
@@ -1728,7 +1730,7 @@
|
||||
var confirmed = await Dialog.ConfirmAsync("Delete Script", $"Delete script '{script.Name}'?", danger: true);
|
||||
if (!confirmed) return;
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await TemplateService.DeleteScriptAsync(script.Id, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.DeleteScriptAsync(script.Id, user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
_toast.ShowSuccess($"Script '{script.Name}' deleted.");
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
@page "/design/templates"
|
||||
@using ZB.MOM.WW.ScadaBridge.CentralUI.Services
|
||||
@using Microsoft.Extensions.DependencyInjection
|
||||
@inject IServiceScopeFactory ScopeFactory
|
||||
@using ZB.MOM.WW.ScadaBridge.Security
|
||||
@using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates
|
||||
@using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories
|
||||
@@ -8,8 +11,6 @@
|
||||
@using ZB.MOM.WW.ScadaBridge.TemplateEngine.Services
|
||||
@attribute [Authorize(Policy = AuthorizationPolicies.RequireDesign)]
|
||||
@inject ITemplateEngineRepository TemplateEngineRepository
|
||||
@inject TemplateService TemplateService
|
||||
@inject TemplateFolderService TemplateFolderService
|
||||
@inject AuthenticationStateProvider AuthStateProvider
|
||||
@inject NavigationManager NavigationManager
|
||||
@inject IDialogService Dialog
|
||||
@@ -355,7 +356,7 @@
|
||||
if (string.IsNullOrWhiteSpace(name)) return;
|
||||
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await TemplateFolderService.CreateFolderAsync(name.Trim(), parentFolderId, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateFolderService svc) => svc.CreateFolderAsync(name.Trim(), parentFolderId, user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
_toast.ShowSuccess($"Folder '{result.Value.Name}' created.");
|
||||
@@ -378,7 +379,7 @@
|
||||
if (result is null) return;
|
||||
|
||||
var user = await GetCurrentUserAsync();
|
||||
var moved = await TemplateService.MoveTemplateAsync(templateId, result.NewFolderId, user);
|
||||
var moved = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.MoveTemplateAsync(templateId, result.NewFolderId, user));
|
||||
if (moved.IsSuccess)
|
||||
{
|
||||
_toast.ShowSuccess($"Template '{label}' moved.");
|
||||
@@ -430,7 +431,7 @@
|
||||
if (result is null) return;
|
||||
|
||||
var user = await GetCurrentUserAsync();
|
||||
var moved = await TemplateFolderService.MoveFolderAsync(folderId, result.NewParentId, user);
|
||||
var moved = await ScopeFactory.InNewScopeAsync((TemplateFolderService svc) => svc.MoveFolderAsync(folderId, result.NewParentId, user));
|
||||
if (moved.IsSuccess)
|
||||
{
|
||||
_toast.ShowSuccess($"Folder '{label}' moved.");
|
||||
@@ -451,7 +452,7 @@
|
||||
private async Task ReorderFolder(int folderId, ReorderDirection direction)
|
||||
{
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await TemplateFolderService.ReorderFolderAsync(folderId, direction, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateFolderService svc) => svc.ReorderFolderAsync(folderId, direction, user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
await LoadTemplatesAsync();
|
||||
@@ -542,7 +543,7 @@
|
||||
if (string.IsNullOrWhiteSpace(newName)) return;
|
||||
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await TemplateFolderService.RenameFolderAsync(folderId, newName, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateFolderService svc) => svc.RenameFolderAsync(folderId, newName, user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
_toast.ShowSuccess("Folder renamed.");
|
||||
@@ -560,7 +561,7 @@
|
||||
if (!confirmed) return;
|
||||
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await TemplateFolderService.DeleteFolderAsync(folderId, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateFolderService svc) => svc.DeleteFolderAsync(folderId, user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
_toast.ShowSuccess($"Folder '{label}' deleted.");
|
||||
@@ -583,7 +584,7 @@
|
||||
try
|
||||
{
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await TemplateService.DeleteTemplateAsync(template.Id, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.DeleteTemplateAsync(template.Id, user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
_toast.ShowSuccess($"Template '{template.Name}' deleted.");
|
||||
@@ -616,7 +617,7 @@
|
||||
if (result is null) return;
|
||||
|
||||
var user = await GetCurrentUserAsync();
|
||||
var composed = await TemplateService.AddCompositionAsync(result.ParentTemplateId, sourceId, result.SlotName, user);
|
||||
var composed = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.AddCompositionAsync(result.ParentTemplateId, sourceId, result.SlotName, user));
|
||||
if (composed.IsSuccess)
|
||||
{
|
||||
_toast.ShowSuccess($"Composed '{sourceName}' as '{result.SlotName}'.");
|
||||
@@ -649,7 +650,7 @@
|
||||
if (string.IsNullOrWhiteSpace(newName) || newName.Trim() == composition.InstanceName) return;
|
||||
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await TemplateService.RenameCompositionAsync(composition.Id, newName.Trim(), user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.RenameCompositionAsync(composition.Id, newName.Trim(), user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
_toast.ShowSuccess($"Slot renamed to '{newName.Trim()}'.");
|
||||
@@ -670,7 +671,7 @@
|
||||
if (!confirmed) return;
|
||||
|
||||
var user = await GetCurrentUserAsync();
|
||||
var result = await TemplateService.DeleteCompositionAsync(composition.Id, user);
|
||||
var result = await ScopeFactory.InNewScopeAsync((TemplateService svc) => svc.DeleteCompositionAsync(composition.Id, user));
|
||||
if (result.IsSuccess)
|
||||
{
|
||||
_toast.ShowSuccess($"Composition '{composition.InstanceName}' removed.");
|
||||
|
||||
+13
-4
@@ -3,7 +3,9 @@ using System.Text.Json;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.AspNetCore.Components.Forms;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ZB.MOM.WW.ScadaBridge.CentralUI.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.CentralUI.Auth;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
||||
@@ -85,6 +87,7 @@ public partial class TransportImport : ComponentBase, IDisposable
|
||||
[Inject] private IOptions<TransportOptions> Options { get; set; } = default!;
|
||||
[Inject] private IAuditService AuditService { get; set; } = default!;
|
||||
[Inject] private ScadaBridgeDbContext DbContext { get; set; } = default!;
|
||||
[Inject] private IServiceScopeFactory ScopeFactory { get; set; } = default!;
|
||||
|
||||
// Register row 44: the per-IP-per-hour unlock throttle needs the caller's
|
||||
// address, and HttpContext is long gone by the time a circuit submits a
|
||||
@@ -870,12 +873,18 @@ public partial class TransportImport : ComponentBase, IDisposable
|
||||
// central-config-only bundles (no required mappings) this is
|
||||
// BundleNameMap.Empty, which the importer normalises away.
|
||||
var nameMap = BuildNameMap();
|
||||
_result = await BundleImporter.ApplyAsync(
|
||||
_session.SessionId,
|
||||
_resolutions.Values.ToList(),
|
||||
// Apply loads and rewrites existing rows, so it runs on its own DI scope
|
||||
// (code review 2026-12-02 UI-1): the circuit's context reads without tracking
|
||||
// and must never carry a write. The session lives in the singleton store, so a
|
||||
// fresh importer instance continues the same session.
|
||||
var sessionId = _session.SessionId;
|
||||
var resolutions = _resolutions.Values.ToList();
|
||||
_result = await ScopeFactory.InNewScopeAsync((IBundleImporter importer) => importer.ApplyAsync(
|
||||
sessionId,
|
||||
resolutions,
|
||||
user,
|
||||
CancellationToken.None,
|
||||
nameMap: nameMap);
|
||||
nameMap: nameMap));
|
||||
_step = ImportWizardStep.Result;
|
||||
}
|
||||
catch (SemanticValidationException ex)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services;
|
||||
using Microsoft.AspNetCore.Components.Authorization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using Microsoft.Extensions.Options;
|
||||
using ZB.MOM.WW.ScadaBridge.CentralUI.Auth;
|
||||
using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Shared;
|
||||
@@ -38,6 +39,12 @@ public static class ServiceCollectionExtensions
|
||||
// Resolves the current user's permitted site set from their SiteId claims
|
||||
// so Deployment/Monitoring pages can enforce site scoping.
|
||||
services.AddScoped<SiteScopeService>();
|
||||
// Code review 2026-12-02 UI-1: the circuit-lifetime configuration DbContext reads
|
||||
// without tracking, so a reload always sees changes made in other scopes. Mutating
|
||||
// page actions run on their own scope (ConfigurationCommandService, the management
|
||||
// actor, or ScopedServiceExtensions.InNewScopeAsync), never on the circuit's context.
|
||||
services.TryAddEnumerable(ServiceDescriptor.Scoped<
|
||||
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHandler, CircuitDbContextTrackingHandler>());
|
||||
services.AddScoped<AuthorizedManualFailoverService>();
|
||||
services.AddScoped<ConfigurationCommandService>();
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
using Microsoft.AspNetCore.Components.Server.Circuits;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Gives each Blazor Server circuit's <see cref="ScadaBridgeDbContext"/> a no-tracking query
|
||||
/// default (code review 2026-12-02, UI-1).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The configuration <see cref="ScadaBridgeDbContext"/> is registered scoped, and in Blazor
|
||||
/// Server one DI scope lives for the whole circuit — hours, across page navigations. With EF's
|
||||
/// default tracking behaviour every entity a page ever loaded stayed in that context's change
|
||||
/// tracker, and a later tracking query for the same key returned the first-loaded instance
|
||||
/// without refreshing its values. Changes made in any other scope (the management actor, another
|
||||
/// user, the CLI, a Transport import) were therefore never seen by the circuit: a moved data
|
||||
/// connection stayed under its old site, a renamed area kept its old name on the live Topology,
|
||||
/// and a template script re-opened after a CLI edit showed — and on save wrote back — the old body.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// Only the circuit's context is switched; contexts in every other scope (management-actor
|
||||
/// commands, the configuration command transaction, HTTP request scopes, hosted services,
|
||||
/// singleton actors) keep EF's tracking default, so the shared services that load-modify-save
|
||||
/// still work there. Page actions that mutate configuration never run on the circuit's context:
|
||||
/// they go through <c>ConfigurationCommandService</c> (its own transaction scope), the
|
||||
/// <c>ManagementActor</c>, or <see cref="ScopedServiceExtensions.InNewScopeAsync{TService, TResult}"/>.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The switch is made in the constructor: the circuit factory resolves every
|
||||
/// <see cref="CircuitHandler"/> from the new circuit's scope while it builds the circuit host,
|
||||
/// before any component is created, so no page query can run on the context first. The context is
|
||||
/// resolved optionally because hosts without the configuration database (tests, a non-central
|
||||
/// role) have none.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed class CircuitDbContextTrackingHandler : CircuitHandler
|
||||
{
|
||||
/// <summary>The query-tracking behaviour every circuit's configuration context runs with.</summary>
|
||||
public const QueryTrackingBehavior CircuitQueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
|
||||
|
||||
/// <summary>Switches the circuit scope's configuration context to the no-tracking default.</summary>
|
||||
/// <param name="circuitServices">The circuit's scoped service provider.</param>
|
||||
public CircuitDbContextTrackingHandler(IServiceProvider circuitServices)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(circuitServices);
|
||||
var context = circuitServices.GetService<ScadaBridgeDbContext>();
|
||||
if (context is not null)
|
||||
context.ChangeTracker.QueryTrackingBehavior = CircuitQueryTrackingBehavior;
|
||||
}
|
||||
|
||||
/// <summary>Runs ahead of other handlers so nothing observes the context first.</summary>
|
||||
public override int Order => int.MinValue;
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace ZB.MOM.WW.ScadaBridge.CentralUI.Services;
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// The circuit's own context runs with a no-tracking default
|
||||
/// (<c>CircuitDbContextTrackingHandler</c>), so a load-modify-save service run on it would
|
||||
/// (<see cref="CircuitDbContextTrackingHandler"/>), so a load-modify-save service run on it would
|
||||
/// silently persist nothing. A fresh scope gets an ordinary tracking context that starts empty,
|
||||
/// so the service always reads the current row and its write lands; the scope is disposed when
|
||||
/// the action ends, so nothing stale is left behind for the next action, and the action does
|
||||
|
||||
+230
@@ -0,0 +1,230 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using Microsoft.AspNetCore.Components.Server.Circuits;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ZB.MOM.WW.ScadaBridge.CentralUI.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Instances;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Sites;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Entities.Templates;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Services;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Templates;
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Interfaces.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Repositories;
|
||||
using ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Services;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Services;
|
||||
|
||||
/// <summary>
|
||||
/// Code review 2026-12-02 UI-1: the circuit-lifetime configuration DbContext served stale
|
||||
/// tracked entities after changes made in another scope. The circuit's context now reads with a
|
||||
/// no-tracking default (<see cref="CircuitDbContextTrackingHandler"/>), contexts in every other
|
||||
/// scope keep EF's tracking default, and no page runs a mutating service on the circuit's context.
|
||||
/// These tests drive the three scenarios from the finding against a real (SQLite) context.
|
||||
/// </summary>
|
||||
public sealed class CircuitDbContextTrackingTests : IDisposable
|
||||
{
|
||||
private readonly SqliteConnection _connection = new("Data Source=:memory:");
|
||||
private readonly ServiceProvider _root;
|
||||
|
||||
public CircuitDbContextTrackingTests()
|
||||
{
|
||||
_connection.Open();
|
||||
var options = new DbContextOptionsBuilder<ScadaBridgeDbContext>().UseSqlite(_connection).Options;
|
||||
var services = new ServiceCollection();
|
||||
services.AddScoped(_ => new ScadaBridgeDbContext(options));
|
||||
services.AddSingleton<ITemplateGraphWatermark, TemplateGraphWatermark>();
|
||||
services.AddScoped<ISiteRepository, SiteRepository>();
|
||||
services.AddScoped<ITemplateEngineRepository, TemplateEngineRepository>();
|
||||
services.AddScoped<CircuitDbContextTrackingHandler>();
|
||||
_root = services.BuildServiceProvider();
|
||||
using var scope = _root.CreateScope();
|
||||
scope.ServiceProvider.GetRequiredService<ScadaBridgeDbContext>().Database.EnsureCreated();
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
_root.Dispose();
|
||||
_connection.Dispose();
|
||||
}
|
||||
|
||||
/// <summary>Opens a scope shaped like a Blazor circuit: the circuit handler is built first.</summary>
|
||||
private IServiceScope OpenCircuitScope(bool withHandler = true)
|
||||
{
|
||||
var scope = _root.CreateScope();
|
||||
if (withHandler)
|
||||
scope.ServiceProvider.GetRequiredService<CircuitDbContextTrackingHandler>();
|
||||
return scope;
|
||||
}
|
||||
|
||||
private async Task InOtherScopeAsync(Func<ScadaBridgeDbContext, Task> change)
|
||||
{
|
||||
using var scope = _root.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<ScadaBridgeDbContext>();
|
||||
await change(db);
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private async Task<(int SiteA, int SiteB, int ConnectionId)> SeedConnectionAsync()
|
||||
{
|
||||
using var scope = _root.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<ScadaBridgeDbContext>();
|
||||
var a = new Site("Site A", "site-a");
|
||||
var b = new Site("Site B", "site-b");
|
||||
db.Sites.AddRange(a, b);
|
||||
await db.SaveChangesAsync();
|
||||
var connection = new DataConnection("PLC", "OpcUa", a.Id);
|
||||
db.DataConnections.Add(connection);
|
||||
await db.SaveChangesAsync();
|
||||
return (a.Id, b.Id, connection.Id);
|
||||
}
|
||||
|
||||
/// <summary>The handler switches only the circuit scope's context; other scopes keep tracking.</summary>
|
||||
[Fact]
|
||||
public void Handler_SetsNoTrackingOnTheCircuitContextOnly()
|
||||
{
|
||||
using var circuit = OpenCircuitScope();
|
||||
using var command = _root.CreateScope();
|
||||
|
||||
Assert.Equal(QueryTrackingBehavior.NoTracking,
|
||||
circuit.ServiceProvider.GetRequiredService<ScadaBridgeDbContext>().ChangeTracker.QueryTrackingBehavior);
|
||||
Assert.Equal(QueryTrackingBehavior.TrackAll,
|
||||
command.ServiceProvider.GetRequiredService<ScadaBridgeDbContext>().ChangeTracker.QueryTrackingBehavior);
|
||||
}
|
||||
|
||||
/// <summary>The handler tolerates a host with no configuration database registered.</summary>
|
||||
[Fact]
|
||||
public void Handler_WithoutAConfigurationDatabase_IsANoOp()
|
||||
{
|
||||
using var empty = new ServiceCollection().BuildServiceProvider();
|
||||
_ = new CircuitDbContextTrackingHandler(empty);
|
||||
}
|
||||
|
||||
/// <summary>AddCentralUI registers the handler as a circuit handler.</summary>
|
||||
[Fact]
|
||||
public void AddCentralUI_RegistersTheTrackingHandler()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddCentralUI();
|
||||
Assert.Contains(services, d => d.ServiceType == typeof(CircuitHandler)
|
||||
&& d.ImplementationType == typeof(CircuitDbContextTrackingHandler)
|
||||
&& d.Lifetime == ServiceLifetime.Scoped);
|
||||
}
|
||||
|
||||
/// <summary>Scenario 1: a data connection moved in another scope shows under its new site.</summary>
|
||||
/// <param name="withHandler">Whether the circuit scope runs the no-tracking handler.</param>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public async Task MovedDataConnection_IsSeenOnReload(bool withHandler)
|
||||
{
|
||||
var (_, siteB, connectionId) = await SeedConnectionAsync();
|
||||
using var circuit = OpenCircuitScope(withHandler);
|
||||
var repo = circuit.ServiceProvider.GetRequiredService<ISiteRepository>();
|
||||
Assert.NotEqual(siteB, (await repo.GetAllDataConnectionsAsync()).Single().SiteId);
|
||||
|
||||
// The Move to Site… dialog moves it through the ManagementActor, i.e. another scope.
|
||||
await InOtherScopeAsync(async db => (await db.DataConnections.SingleAsync(c => c.Id == connectionId)).SiteId = siteB);
|
||||
|
||||
var reloaded = (await repo.GetAllDataConnectionsAsync()).Single().SiteId;
|
||||
if (withHandler)
|
||||
Assert.Equal(siteB, reloaded);
|
||||
else
|
||||
Assert.NotEqual(siteB, reloaded); // the pre-fix behaviour this guards against
|
||||
}
|
||||
|
||||
/// <summary>Scenario 2: a renamed / re-parented area is seen by the next Topology refresh.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task RenamedArea_IsSeenOnRefresh()
|
||||
{
|
||||
var (siteA, _, _) = await SeedConnectionAsync();
|
||||
int areaId;
|
||||
using (var seed = _root.CreateScope())
|
||||
{
|
||||
var db = seed.ServiceProvider.GetRequiredService<ScadaBridgeDbContext>();
|
||||
var area = new Area("Line 1") { SiteId = siteA };
|
||||
db.Areas.Add(area);
|
||||
await db.SaveChangesAsync();
|
||||
areaId = area.Id;
|
||||
}
|
||||
|
||||
using var circuit = OpenCircuitScope();
|
||||
var repo = circuit.ServiceProvider.GetRequiredService<ITemplateEngineRepository>();
|
||||
Assert.Equal("Line 1", (await repo.GetAreasBySiteIdAsync(siteA)).Single().Name);
|
||||
|
||||
await InOtherScopeAsync(async db => (await db.Areas.SingleAsync(a => a.Id == areaId)).Name = "Line 1 (renamed)");
|
||||
|
||||
Assert.Equal("Line 1 (renamed)", (await repo.GetAreasBySiteIdAsync(siteA)).Single().Name);
|
||||
}
|
||||
|
||||
/// <summary>Scenario 3: a script edited by the CLI / an import is what the editor reloads.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[Fact]
|
||||
public async Task ScriptEditedElsewhere_IsWhatTheEditorReloads()
|
||||
{
|
||||
int templateId, scriptId;
|
||||
using (var seed = _root.CreateScope())
|
||||
{
|
||||
var db = seed.ServiceProvider.GetRequiredService<ScadaBridgeDbContext>();
|
||||
var template = new Template("Pump");
|
||||
template.Scripts.Add(new TemplateScript("OnStart", "return 1;"));
|
||||
db.Templates.Add(template);
|
||||
await db.SaveChangesAsync();
|
||||
templateId = template.Id;
|
||||
scriptId = template.Scripts.Single().Id;
|
||||
}
|
||||
|
||||
using var circuit = OpenCircuitScope();
|
||||
var repo = circuit.ServiceProvider.GetRequiredService<ITemplateEngineRepository>();
|
||||
Assert.Equal("return 1;", (await repo.GetTemplateWithChildrenAsync(templateId))!.Scripts.Single().Code);
|
||||
|
||||
await InOtherScopeAsync(async db => (await db.TemplateScripts.SingleAsync(s => s.Id == scriptId)).Code = "return 2;");
|
||||
|
||||
Assert.Equal("return 2;", (await repo.GetScriptsByTemplateIdAsync(templateId)).Single().Code);
|
||||
Assert.Equal("return 2;", (await repo.GetTemplateWithChildrenAsync(templateId))!.Scripts.Single().Code);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The circuit's context reads without tracking, so a load-modify-save service run on it
|
||||
/// would silently persist nothing. Guard: no CentralUI page or component calls a mutating
|
||||
/// method on a circuit-injected instance of one of the load-modify-save services; those calls
|
||||
/// go through <see cref="ScopedServiceExtensions.InNewScopeAsync{TService, TResult}"/> (or the
|
||||
/// configuration command boundary).
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void NoPageMutatesThroughACircuitInjectedLoadModifySaveService()
|
||||
{
|
||||
var root = AppContext.BaseDirectory;
|
||||
for (var i = 0; i < 6; i++) root = Directory.GetParent(root)!.FullName;
|
||||
var uiRoot = Path.Combine(root, "src", "ZB.MOM.WW.ScadaBridge.CentralUI");
|
||||
Assert.True(Directory.Exists(uiRoot), uiRoot);
|
||||
|
||||
const string ServiceTypes = "TemplateService|TemplateFolderService|SharedScriptService|InstanceService|AreaService|"
|
||||
+ "SiteService|DeploymentService|ArtifactDeploymentService|IBundleImporter|TemplateDeletionService";
|
||||
var injected = new Regex(
|
||||
@"(?:@inject\s+(?:[\w.]+\.)?(?<type>" + ServiceTypes + @")\s+(?<name>\w+))"
|
||||
+ @"|(?:\[Inject\]\s*(?:private|public|protected|internal)?\s*(?:[\w.]+\.)?(?<type>" + ServiceTypes + @")\s+(?<name>\w+))");
|
||||
var offenders = new List<string>();
|
||||
foreach (var file in Directory.EnumerateFiles(uiRoot, "*.*", SearchOption.AllDirectories)
|
||||
.Where(f => f.EndsWith(".razor", StringComparison.Ordinal) || f.EndsWith(".razor.cs", StringComparison.Ordinal))
|
||||
.Where(f => !f.Contains($"{Path.DirectorySeparatorChar}obj{Path.DirectorySeparatorChar}", StringComparison.Ordinal)))
|
||||
{
|
||||
var text = File.ReadAllText(file);
|
||||
foreach (Match m in injected.Matches(text))
|
||||
{
|
||||
var name = m.Groups["name"].Value;
|
||||
var mutation = new Regex(@"\b" + Regex.Escape(name)
|
||||
+ @"\.(?:Create|Update|Delete|Add|Remove|Move|Rename|Reorder|Resync|Set|Enable|Disable|Deploy|Retry|Apply|Import)\w*\(");
|
||||
foreach (Match call in mutation.Matches(text))
|
||||
offenders.Add($"{Path.GetFileName(file)}: {call.Value}");
|
||||
}
|
||||
}
|
||||
|
||||
Assert.True(offenders.Count == 0,
|
||||
"Mutating call on a circuit-scoped service (run it via ScopeFactory.InNewScopeAsync instead): "
|
||||
+ string.Join("; ", offenders));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user