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.
|
/// rows to the pure <see cref="UnsTreeAssembly.Build"/> to nest into the browse tree.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <remarks>
|
/// <remarks>
|
||||||
/// A new context is created per call via the pooled factory — the same pattern every
|
/// Each call creates and disposes its own context via the pooled factory — the same pattern
|
||||||
/// AdminUI page uses — so the service is safe to register as a scoped singleton and call
|
/// every AdminUI page uses — so the service is safe to register as Scoped and used per
|
||||||
/// concurrently from independent Blazor circuits.
|
/// Blazor circuit.
|
||||||
/// </remarks>
|
/// </remarks>
|
||||||
public sealed class UnsTreeService(IDbContextFactory<OtOpcUaConfigDbContext> dbFactory) : IUnsTreeService
|
public sealed class UnsTreeService(IDbContextFactory<OtOpcUaConfigDbContext> dbFactory) : IUnsTreeService
|
||||||
{
|
{
|
||||||
@@ -55,11 +55,12 @@ public sealed class UnsTreeService(IDbContextFactory<OtOpcUaConfigDbContext> dbF
|
|||||||
.ToListAsync(ct))
|
.ToListAsync(ct))
|
||||||
.ToDictionary(x => x.EquipmentId, x => x.Count, StringComparer.Ordinal);
|
.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
|
var vtagCounts = (await db.VirtualTags
|
||||||
.AsNoTracking()
|
.AsNoTracking()
|
||||||
|
.Where(v => v.EquipmentId != null)
|
||||||
.GroupBy(v => v.EquipmentId)
|
.GroupBy(v => v.EquipmentId)
|
||||||
.Select(g => new { EquipmentId = g.Key, Count = g.Count() })
|
.Select(g => new { EquipmentId = g.Key!, Count = g.Count() })
|
||||||
.ToListAsync(ct))
|
.ToListAsync(ct))
|
||||||
.ToDictionary(x => x.EquipmentId, x => x.Count, StringComparer.Ordinal);
|
.ToDictionary(x => x.EquipmentId, x => x.Count, StringComparer.Ordinal);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user