Spring.NET 1.3.0 RC1 for .NET 2.0 API Reference

IObjectFactory.GetObject(String, Type) Method

Return an instance (possibly shared or independent) of the given object name.

[Visual Basic]
Public Sub GetObject( _
   ByVal name As String, _
   ByVal requiredType As Type _
object GetObject(
   string name,
   Type requiredType


The name of the object to return.
Type the object may match. Can be an interface or superclass of the actual class. For example, if the value is the Object class, this method will succeed whatever the class of the returned instance.

Return Value

The instance of the object.


Provides a measure of type safety by throwing an exception if the object is not of the required Type.

This method allows an object factory to be used as a replacement for the Singleton or Prototype design pattern.

Note that callers should retain references to returned objects. There is no guarantee that this method will be implemented to be efficient. For example, it may be synchronized, or may need to run an RDBMS query.

Will ask the parent factory if the object cannot be found in this factory instance.


Exception Type Condition
NoSuchObjectDefinitionException If there's no such object definition.
ObjectsException If the object could not be created.
ObjectNotOfRequiredTypeException If the object is not of the required type.

See Also

IObjectFactory Interface | Spring.Objects.Factory Namespace | IObjectFactory.GetObject Overload List