Beispiel #1
0
        protected override IEnumerable <Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            var contractName = definition.ContractName;

            if (contractName == typeof(IIOFactory).FullName)
            {
                yield return(new Export(contractName, () => FIOFactory));
            }
            else
            {
                var typeToExport = ExportProviderUtils.GetImportDefinitionType(definition);

                foreach (var attribute in ExportProviderUtils.GetImportDefinitionAttributes(definition))
                {
                    var ioAttribute = attribute as IOAttribute;
                    if (ioAttribute == null)
                    {
                        continue;
                    }

                    var context = IOBuildContext.Create(typeToExport, ioAttribute);
                    if (FIOFactory.CanCreateIOContainer(context))
                    {
                        yield return(new Export(contractName, () => FIOFactory.CreateIO(context)));

                        yield break;
                    }
                }
            }
        }
Beispiel #2
0
        protected override IEnumerable <Export> GetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
        {
            Export export;

            if (!FExports.TryGetValue(definition, out export))
            {
                var contractName = definition.ContractName;
                if (contractName == typeof(IIOFactory).FullName)
                {
                    export = new Export(contractName, () => FIOFactory);
                }
                else
                {
                    var typeToExport = ExportProviderUtils.GetImportDefinitionType(definition);

                    foreach (var attribute in ExportProviderUtils.GetImportDefinitionAttributes(definition))
                    {
                        var ioAttribute = attribute as IOAttribute;
                        if (ioAttribute == null)
                        {
                            continue;
                        }

                        if (!ReflectionModelServices.IsImportingParameter(definition))
                        {
                            var member = ReflectionModelServices.GetImportingMember(definition);
                            if (member.MemberType == MemberTypes.Property)
                            {
                                foreach (var accessor in member.GetAccessors())
                                {
                                    if (FAccessorToExportMap.TryGetValue(accessor, out export))
                                    {
                                        break;
                                    }
                                }
                            }
                        }
                        if (export == null)
                        {
                            var context = IOBuildContext.Create(typeToExport, ioAttribute);
                            if (FIOFactory.CanCreateIOContainer(context))
                            {
                                export = new Export(contractName, () => FIOFactory.CreateIO(context));
                                // Now register the export for all the base members
                                if (!ReflectionModelServices.IsImportingParameter(definition))
                                {
                                    var member = ReflectionModelServices.GetImportingMember(definition);
                                    if (member.MemberType == MemberTypes.Property)
                                    {
                                        foreach (var accessor in member.GetAccessors().OfType <MethodInfo>())
                                        {
                                            RegisterExport(accessor, export);
                                        }
                                    }
                                }
                            }
                        }
                        if (export != null)
                        {
                            break;
                        }
                    }
                }
                FExports.Add(definition, export);
            }
            if (export != null)
            {
                yield return(export);
            }
        }