refactor(uns): clarify service lifetime doc + defensive vtag-count null filter (review)
This commit is contained in:
@@ -9,9 +9,9 @@ namespace ZB.MOM.WW.OtOpcUa.AdminUI.Uns;
|
||||
/// rows to the pure <see cref="UnsTreeAssembly.Build"/> to nest into the browse tree.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// A new context is created per call via the pooled factory — the same pattern every
|
||||
/// AdminUI page uses — so the service is safe to register as a scoped singleton and call
|
||||
/// concurrently from independent Blazor circuits.
|
||||
/// Each call creates and disposes its own context via the pooled factory — the same pattern
|
||||
/// every AdminUI page uses — so the service is safe to register as Scoped and used per
|
||||
/// Blazor circuit.
|
||||
/// </remarks>
|
||||
public sealed class UnsTreeService(IDbContextFactory<OtOpcUaConfigDbContext> dbFactory) : IUnsTreeService
|
||||
{
|
||||
@@ -55,11 +55,12 @@ public sealed class UnsTreeService(IDbContextFactory<OtOpcUaConfigDbContext> dbF
|
||||
.ToListAsync(ct))
|
||||
.ToDictionary(x => x.EquipmentId, x => x.Count, StringComparer.Ordinal);
|
||||
|
||||
// Per-equipment virtual-tag counts (EquipmentId is always set on virtual tags).
|
||||
// Per-equipment virtual-tag counts (virtual tags with no equipment are excluded).
|
||||
var vtagCounts = (await db.VirtualTags
|
||||
.AsNoTracking()
|
||||
.Where(v => v.EquipmentId != null)
|
||||
.GroupBy(v => v.EquipmentId)
|
||||
.Select(g => new { EquipmentId = g.Key, Count = g.Count() })
|
||||
.Select(g => new { EquipmentId = g.Key!, Count = g.Count() })
|
||||
.ToListAsync(ct))
|
||||
.ToDictionary(x => x.EquipmentId, x => x.Count, StringComparer.Ordinal);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user