public bool TryGetExport(Type type, Type injectTargetType, List <Type> pendingCreateList, out object instance) { if (discoveryConditionItems != null) { DiscoveryContext ctx = new DiscoveryContext(type, injectTargetType); foreach (var cond in discoveryConditionItems) { if (cond.IsMatching(ctx)) { return(cond.TargetContainer.TryGetExport(type, injectTargetType, out instance)); } } } if (localShare.SharedLocalInstances.TryGetValue(type, out instance)) { return(true); } if (hostSessionsSharedInstances.TryGetValue(type, out instance)) { return(true); } Type targetType; var contract = currentContract; if (type.IsInterface) { if (contract != null) { if (contract.TryGetSessionInstance(type, out instance)) { return(true); } } if (!localShare.TryFindInterfaceImplementation(type, injectTargetType, out targetType)) { // not found > check if multiple import if (type.GetInterface(typeof(System.Collections.IEnumerable).FullName) != null) { var multiImportColl = localShare.CollectLocalMultiImports(this, type, injectTargetType, pendingCreateList); if (multiImportColl != null) { instance = multiImportColl; return(true); } } else { instance = null; return(false); } } } else if (type.IsArray) { var multiImportColl = this.localShare.CollectLocalMultiImports(this, type, injectTargetType, pendingCreateList); if (multiImportColl != null) { instance = multiImportColl; return(true); } else { instance = null; return(false); } } else { targetType = type; } object[] outParams; ParameterInfo[] outParamsInfo; instance = TypeService.CreateInstance(targetType, DetermineConstructorImportInstance, pendingCreateList, out outParams, out outParamsInfo); localShare.CheckOutParamsSubscriptions(instance, outParams, this, type); localShare.RegisterSharedConstructorInstances(type, instance, outParams, outParamsInfo); if (contract != null && this.localSessionServiceInterfaceTypesResolved.Contains(type)) { // update contract service cache here as well to be not dependent on the registration order in nested cases int cachedAtIndex = Array.IndexOf <Type>(this.localSessionServiceInterfaceTypesResolved, type); contract.LocalServices[cachedAtIndex] = instance; } //todo: parent container handling return(true); }
public bool TryGetExport(Type type, Type injectTargetType, List <Type> pendingCreateList, out object instance) { if (discoveryConditionItems != null) { DiscoveryContext ctx = new DiscoveryContext(type, injectTargetType); foreach (var cond in discoveryConditionItems) { if (cond.IsMatching(ctx)) { return(cond.TargetContainer.TryGetExport(type, injectTargetType, out instance)); } } } if (this.SharedLocalInstances.TryGetValue(type, out instance)) { return(true); } //if (hostSessionsSharedInstances.TryGetValue(type, out instance)) //{ // return true; //} if (ParentContainer != null && ParentContainer is IContainerSharedByType parentShared && parentShared.TryGetCachedLocalExport(type, out instance)) { return(true); } // create new instance Type targetType; if (type.IsInterface) { //var contract = currentContract; //if (contract != null) //{ // if (contract.TryGetSessionInstance(type, out instance)) // { // return true; // } //} if (!TryFindInterfaceImplementation(type, injectTargetType, out targetType)) { // not found > check if multiple import if (type.GetInterface(typeof(System.Collections.IEnumerable).FullName) != null) { var multiImportColl = this.CollectLocalMultiImports(null, type, injectTargetType, pendingCreateList); if (multiImportColl != null) { instance = multiImportColl; return(true); } // todo: else? } else { instance = null; return(false); } } } else if (type.IsArray) { var multiImportColl = this.CollectLocalMultiImports(null, type, injectTargetType, pendingCreateList); if (multiImportColl != null) { instance = multiImportColl; return(true); } else { instance = null; return(false); } } else { targetType = type; } object[] outParams; ParameterInfo[] outParamsInfo; instance = TypeService.CreateInstance(targetType, DetermineConstructorImportInstance, pendingCreateList, out outParams, out outParamsInfo); this.CheckOutParamsSubscriptions(instance, outParams, null, type); this.RegisterSharedConstructorInstances(type, instance, outParams, outParamsInfo); return(true); }