internal FactoryTypeInfoInternal(string contractName, FactoryCreationPolicy creationPolicy, Type type, Func <object[], object> createInstance) { this.ContractName = contractName; this.CreationPolicy = creationPolicy; this.Type = type; this.createInstance = createInstance; }
internal FactoryTypeInfoInternal(string contractName, FactoryCreationPolicy creationPolicy, Type type, Func <object[], object> createInstance) { this.ContractName = contractName; this.CreationPolicy = creationPolicy; this.Type = type; this.createInstance = createInstance; this.IsEnumerable = type.IsArray || type.ImplementsInterface(typeof(IEnumerable)); this.ChildType = type.GetChildrenType(); }
/// <summary> /// Adds a new <see cref="Type"/> to list of known types. Should only be used for unit-tests /// </summary> /// <threadsafety static="false" instance="false"/> /// <param name="contractName">The name that identifies the type</param> /// <param name="creationPolicy">The creation policy of the type as defined by <see cref="FactoryCreationPolicy"/></param> /// <param name="type">The type to be added</param> /// <param name="createInstance"> /// An action that is called by the factory to create the object /// </param> public static IFactoryTypeInfo AddType(string contractName, FactoryCreationPolicy creationPolicy, Type type, Func <object[], object> createInstance) { var factoryTypeInfo = new FactoryTypeInfoInternal(contractName, creationPolicy, type, createInstance); if (components.ContainsKey(contractName)) { var content = components[contractName]; components[contractName] = content.Concat(factoryTypeInfo); return(factoryTypeInfo); } components.Add(contractName, new IFactoryTypeInfo[] { factoryTypeInfo }); return(factoryTypeInfo); }
/// <summary> /// Initializes an instance of <see cref="ComponentAttribute"/> /// </summary> /// <param name="contractName">The contract name that is used to export the type</param> /// <param name="policy">The creation policy</param> /// <param name="priority">The priority of the component. The <see cref="Factory"/> uses this information to sort the instances for <see cref="Factory.CreateMany(string, object[])"/></param>. 0 is lowest; uint.Max is highest. /// <exception cref="ArgumentNullException">Parameter <paramref name="contractName"/> is null</exception> /// <exception cref="ArgumentException">Parameter <paramref name="contractName"/> is empty</exception> public ComponentAttribute(string contractName, FactoryCreationPolicy policy, uint priority) { if (contractName == null) { throw new ArgumentNullException(nameof(contractName)); } if (contractName.Length == 0) { throw new ArgumentException("The parameter is an empty string", nameof(contractName)); } this.Policy = policy; this.ContractName = contractName; this.Priority = priority; }
/// <summary> /// Initializes an instance of <see cref="ComponentAttribute"/>. The default <see cref="ComponentAttribute.Priority"/> is 0. /// </summary> /// <param name="contractType">A type from which to derive the contract name that is used to export the type</param> /// <param name="policy">The creation policy</param> public ComponentAttribute(Type contractType, FactoryCreationPolicy policy) : this(contractType.FullName, policy, 0) { }
/// <summary> /// Initializes an instance of <see cref="GenericComponentAttribute"/> /// </summary> /// <param name="type">The generic type to be defined as component.</param> /// <param name="contractName">The contract name that is used to export the type</param> /// <param name="policy">The creation policy</param> /// <param name="priority">The priority of the component. The <see cref="Factory"/> uses this information to sort the instances for <see cref="Factory.CreateMany(string, object[])"/></param>. 0 is lowest; uint.Max is highest. public GenericComponentAttribute(Type type, string contractName, FactoryCreationPolicy policy, uint priority) : base(contractName, policy, priority) { }
/// <summary> /// Initializes an instance of <see cref="GenericComponentAttribute"/> /// </summary> /// <param name="type">The generic type to be defined as component.</param> /// <param name="contractName">The contract name that is used to export the type</param> /// <param name="policy">The creation policy</param> public GenericComponentAttribute(Type type, string contractName, FactoryCreationPolicy policy) : this(type, contractName, policy, 0) { }
/// <summary> /// Initializes an instance of <see cref="GenericComponentAttribute"/> /// </summary> /// <param name="type">The generic type to be defined as component.</param> /// <param name="contractType">A type from which to derive the contract name that is used to export the type</param> /// <param name="policy">The creation policy</param> /// <param name="priority">The priority of the component. The <see cref="Factory"/> uses this information to sort the instances for <see cref="Factory.CreateMany(string, object[])"/></param>. 0 is lowest; uint.Max is highest. public GenericComponentAttribute(Type type, Type contractType, FactoryCreationPolicy policy, uint priority) : this(type, contractType.FullName, policy, priority) { }