using C4IT.FASD.Base; using FasdDesktopUi.Basics.Services.RelationService; using System; using System.Collections.Generic; using System.ComponentModel; namespace FasdDesktopUi.Basics.Services.SupportCase { public static class SupportCaseFactory { private static readonly Dictionary _supportCases = new Dictionary(); private static ISupportCase Create(cF4sdIdentityEntry primaryIdentity, IRelationService relationService, cSupportCaseDataProvider supportCaseDataProvider) { SupportCase supportCase = new SupportCase(primaryIdentity.Id, relationService, supportCaseDataProvider); _supportCases.Add(primaryIdentity.Id, supportCase); supportCase.Initialize(); return supportCase; } public static ISupportCase Get(cF4sdIdentityEntry primaryIdentity, IRelationService relationService, cSupportCaseDataProvider supportCaseDataProvider) { if (primaryIdentity is null) throw new InvalidEnumArgumentException($"{nameof(primaryIdentity)} must not be null."); if (_supportCases.TryGetValue(primaryIdentity.Id, out var supportCase)) { supportCase.Initialize(); return supportCase; } return Create(primaryIdentity, relationService, supportCaseDataProvider); } } }