예제 #1
0
        CompositionContract MapExportedContract(ExportDefinition export, Func <string, Type> typeNameResolver)
        {
            object typeId;

            if (!export.Metadata.TryGetValue(CompositionConstants.ExportTypeIdentityMetadataName, out typeId) ||
                !(typeId is string))
            {
                throw new NotSupportedException("Only typed exports are supported.");
            }

            var contractType = typeNameResolver(PrimitiveAdaptation.ParseTypeIdentity((string)typeId));
            var contractName = export.ContractName.Equals(typeId) ? null : export.ContractName;

            return(new CompositionContract(contractType, contractName));
        }
예제 #2
0
        CompositionContract ImportDefinitionToContract(ContractBasedImportDefinition cbid)
        {
            var typeId = cbid.RequiredTypeIdentity;

            if (typeId == null)
            {
                throw new CompositionFailedException("Dynamic or 'object' imports are not supported'.");
            }

            var contractType = _typeNameResolver(PrimitiveAdaptation.ParseTypeIdentity(typeId));
            var contractName = cbid.ContractName.Equals(typeId) ? null : cbid.ContractName;

            if (cbid.RequiredCreationPolicy != CreationPolicy.Any)
            {
                throw new CompositionFailedException("Required creation policy cannot be specified.");
            }

            // Required metadata is ignored; we will let the primitives fail later.

            return(new CompositionContract(contractType, contractName));
        }