|Visual Basic (Declaration)|
<DefaultMemberAttribute("Item")> Public Interface IObjectFactory
|Visual Basic (Usage)||Copy Code|
[DefaultMemberAttribute("Item")] public interface IObjectFactory
This is the basic client view of a Spring.NET IoC container; further interfaces such as Spring.Objects.Factory.IListableObjectFactory and Spring.Objects.Factory.Config.IConfigurableObjectFactory are available for specific purposes such as enumeration and configuration.
This is the root interface to be implemented by objects that can hold a number of object definitions, each uniquely identified by a String name. An independent instance of any of these objects can be obtained (the Prototype design pattern), or a single shared instance can be obtained (a superior alternative to the Singleton design pattern, in which the instance is a singleton in the scope of the factory). Which type of instance will be returned depends on the object factory configuration - the API is the same. The Singleton approach is more useful and hence more common in practice.
The point of this approach is that the IObjectFactory is a central registry of application components, and centralizes the configuring of application components (no more do individual objects need to read properties files, for example). See chapters 4 and 11 of "Expert One-on-One J2EE Design and Development" for a discussion of the benefits of this approach.
Normally an IObjectFactory will load object definitions stored in a configuration source (such as an XML document), and use the Spring.Objects Namespace namespace to configure the objects. However, an implementation could simply return .NET objects it creates as necessary directly in .NET code. There are no constraints on how the definitions could be stored: LDAP, RDBMS, XML, properties file etc. Implementations are encouraged to support references amongst objects, to either Singletons or Prototypes.
In contrast to the methods in Spring.Objects.Factory.IListableObjectFactory, all of the methods in this interface will also check parent factories if this is an Spring.Objects.Factory.IHierarchicalObjectFactory. If an object is not found in this factory instance, the immediate parent is asked. Objects in this factory instance are supposed to override objects of the same name in any parent factory.
Object factories are supposed to support the standard object lifecycle interfaces as far as possible. The maximum set of initialization methods and their standard order is:
IObjectNameAware's IObjectNameAware.ObjectName property. IObjectFactoryAware's IObjectFactoryAware.ObjectFactory property. IApplicationContextAware.ApplicationContext (only applicable if running within an IApplicationContext). The IObjectPostProcessor.PostProcessBeforeInitialization method of Spring.Objects.Factory.Config.IObjectPostProcessors. Spring.Objects.Factory.IInitializingObject's Spring.Objects.Factory.IInitializingObject.AfterPropertiesSet method. A custom init-method definition. The IObjectPostProcessor.PostProcessAfterInitialization method of Spring.Objects.Factory.Config.IObjectPostProcessors.
On shutdown of an object factory, the following lifecycle methods apply:
Platforms:Windows XP Professional, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7
Assembly: Spring.Core (in Spring.Core.dll)