/// <inheritdoc/> public RegistryEventReference AddEventInstance(IRegistryEvent effect) { int effectTypeId = RegistryEventReference.GetTypeId(effect.GetType()); int effectVersionId = RegistryEventReference.GetEffectInstanceId(effect); // Lazy initialzation if (!registar.ContainsKey(effectTypeId)) { // Using Concurrent version of the dictionary to ovoid problem of reading while writing event though it should not happen. registar[effectTypeId] = new ConcurrentDictionary <int, IRegistryEvent>(); } // Avoid duplicates if (!registar[effectTypeId].ContainsKey(effectVersionId)) { registar[effectTypeId].TryAdd(effectVersionId, effect); OnNewElementRegistered(); } return(new RegistryEventReference() { TypeId = effectTypeId, VersionId = effectVersionId }); }