Spring.NET 1.3.0 RC1 for .NET 2.0 API Reference

ObjectDefinitionConstants.FactoryMethodAttribute Field

Optional attribute specifying the name of a factory method to use to create this object.

[Visual Basic]
Public Const FactoryMethodAttribute As String = factory-method
[C#]
public const string FactoryMethodAttribute = factory-method;

Remarks

Use constructor-arg elements to specify arguments to the factory method, if it takes arguments. Autowiring does not apply to factory methods.

If the "type" attribute is present, the factory method will be a static method on the type specified by the "type" attribute on this object definition. Often this will be the same type as that of the constructed object - for example, when the factory method is used as an alternative to a constructor. However, it may be on a different type. In that case, the created object will *not* be of the type specified in the "type" attribute. This is analogous to IFactoryObject behaviour.

If the "factory-object" attribute is present, the "type" attribute is not used, and the factory method will be an instance method on the object returned from a GetObject call with the specified object name. The factory object may be defined as a singleton or a prototype.

The factory method can have any number of arguments. Use indexed constructor-arg elements in conjunction with the factory-method attribute.

Setter Injection can be used in conjunction with a factory method. Method Injection cannot, as the factory method returns an instance, which will be used when the container creates the object.

See Also

ObjectDefinitionConstants Class | Spring.Objects.Factory.Xml Namespace