Spring.NET 1.3.0 RC1 for .NET 2.0 API Reference

IObjectFactory.ConfigureObject Method

Injects dependencies into the supplied target instance using the named object definition.

[Visual Basic]
Public Sub ConfigureObject( _
   ByVal target As Object, _
   ByVal name As String _
object ConfigureObject(
   object target,
   string name


The object instance that is to be so configured.
The name of the object definition expressing the dependencies that are to be injected into the supplied instance.


In addition to being generally useful, typically this method is used to provide dependency injection functionality for objects that are instantiated outwith the control of a developer. A case in point is the way that the current (1.1) ASP.NET classes instantiate web controls... the instantiation takes place within a private method of a compiled page, and thus cannot be hooked into the typical Spring.NET IOC container lifecycle for dependency injection.


Exception Type Condition
NoSuchObjectDefinitionException If there is no object definition for the supplied name.
ObjectsException If any of the target object's dependencies could not be created.


The following code snippet assumes that the instantiated factory instance has been configured with an object definition named 'ExampleNamespace.BusinessObject' that has been configured to set the Dao property of any ExampleNamespace.BusinessObject instance to an instance of an appropriate implementation...

namespace ExampleNamespace
    public class BusinessObject
        private IDao _dao;
        public BusinessObject() {}

        public IDao Dao
            get { return _dao;    }
            set { _dao = value; }
with the corresponding driver code looking like so...
IObjectFactory factory = GetAnIObjectFactoryImplementation();
BusinessObject instance = new BusinessObject();
factory.ConfigureObject(instance, "object_definition_name");
// at this point the dependencies for the 'instance' object will have been resolved...

See Also

IObjectFactory Interface | Spring.Objects.Factory Namespace