private void ConstructInstance(PartCompositionId partId) { if (CanPartBeInstantiated(partId)) { var satisfiedPartImports = SatisfiedPartImports(partId); foreach (var importPair in satisfiedPartImports) { var exportingPartInfo = m_Parts[importPair.Item2]; if (exportingPartInfo.Instance == null) { ConstructInstance(importPair.Item2); } } var partImports = ImportInformationForPart(satisfiedPartImports); var info = m_Parts[partId]; if (info.Instance != null) { var updatedInstances = Instances.UpdateIfRequired(info.Instance, partImports); foreach (var instance in updatedInstances) { if (instance.Change == InstanceChange.Removed) { var updatedInfo = m_Parts.FirstOrDefault(p => instance.Instance.Equals(p.Value.Instance)); updatedInfo.Value.Instance = null; } } } else { info.Instance = Instances.Construct( info.Definition, partImports); } } }