private IComponentFactory CreateDefaultFactory(Type component) { IComponentFactory result; if ((component.IsGenericType) && (component.ContainsGenericParameters)) { result = new GenericLocalComponentFactory(component); } else { result = new LocalComponentFactory(component); } return(result); }
internal static ILocalComponentFactory CreateLocalFactory(Type component) { ILocalComponentFactory result; if ((component.IsGenericType) && (component.ContainsGenericParameters)) { result = new GenericLocalComponentFactory(component); } else { result = new LocalComponentFactory(component); } return(result); }
internal static ILocalComponentFactory CreateLocalFactory(Type component) { ILocalComponentFactory result; if (component.IsOpenGenericType()) { result = new GenericLocalComponentFactory(component); } else { result = new LocalComponentFactory(component); } return(result); }
private static void RunRegisterComponent(CompositionCommandInfo info, XmlProcessingContext xmlProcessingContext) { if (!(info is RegisterComponentInfo registerComponentInfo)) { throw new ArgumentException("Invalid runner input type: error in static setup."); } // Extract and load contract type Type contractType = null; if (registerComponentInfo.ContractType != null) { contractType = SimpleTypeParserUtil.ParseType(registerComponentInfo.ContractType, xmlProcessingContext); if (contractType == null) { xmlProcessingContext.ReportError( $"Type '{registerComponentInfo.ContractType}' could not be loaded."); return; } } // Get contract name var contractName = registerComponentInfo.ContractName; // Build ComponentConfiguration var componentType = SimpleTypeParserUtil.ParseType(registerComponentInfo.Type, xmlProcessingContext); if (componentType == null) { xmlProcessingContext.ReportError($"Type '{registerComponentInfo.Type}' could not be loaded."); return; } IComponentFactory componentFactory; List <InitializationPointSpecification> initializationPoints; if ((componentType.IsGenericType) && (componentType.ContainsGenericParameters)) { var genericLocalComponentFactory = new GenericLocalComponentFactory(componentType); componentFactory = genericLocalComponentFactory; initializationPoints = genericLocalComponentFactory.InitializationPoints; } else { var localComponentFactory = new LocalComponentFactory(componentType); componentFactory = localComponentFactory; initializationPoints = localComponentFactory.InitializationPoints; } // Add each configured plug, into the InitializationPoints // in the component configuration. foreach (var plugInfo in registerComponentInfo.Plugs) { xmlProcessingContext.EnterRunningLocation($"Plug '{plugInfo.Name}'"); var plugRefType = SimpleTypeParserUtil.ParseType(plugInfo.RefType, xmlProcessingContext); if (plugRefType == null) { xmlProcessingContext.ReportError($"Type '{plugInfo.RefType}' could not be loaded."); xmlProcessingContext.LeaveRunningLocation(); return; } var plugRefName = plugInfo.RefName; initializationPoints.Add(new InitializationPointSpecification( plugInfo.Name, MemberTypes.All, true, new ComponentQuery(plugRefType, plugRefName))); // TODO: Add support for optional plugs in Composition XML xmlProcessingContext.LeaveRunningLocation(); } // Add each configuration point, into the InitializationPoints // in the component configuration. foreach (var configurationPointInfo in registerComponentInfo.ConfigurationPoints) { xmlProcessingContext.EnterRunningLocation($"ConfigurationPoint '{configurationPointInfo.Name}'"); var value = CreateLazyXmlValue(configurationPointInfo.XElements, configurationPointInfo.XAttributes, xmlProcessingContext); initializationPoints.Add(new InitializationPointSpecification( configurationPointInfo.Name, MemberTypes.All, true, new LazyValueQuery(value))); xmlProcessingContext.LeaveRunningLocation(); } // Register the component into the component context. if (contractType == null) { xmlProcessingContext.ComponentContext.Register(contractName, componentFactory); } else { xmlProcessingContext.ComponentContext.Register(contractType, contractName, componentFactory); } }
public FluentGenericLocalComponentConfig(ComponentContext context, GenericLocalComponentFactory factory) { Context = context ?? throw new ArgumentNullException(nameof(context)); Factory = factory ?? throw new ArgumentNullException(nameof(factory)); }