wbgu's技术小屋

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 为了从设计的角度理解Spring.Net FrameWork,个人觉得可以先从接口设计入手,本文从Object模块入手,摘录Object接口说明文档,一来是对Object模块的接口实际有一个全面的了解,二来也是为了提高自身英文水平,故基本采用英文格式,权当个人笔记。

1.   Spring.Objects Namespace

Contains interfaces and classes for manipulating plain old .NET objects (PONOs).

The classes and interfaces declared in this namespace are central to Spring.NET's Inversion of Control (IoC) container implementation.

num

interface

Reference & relation

description

1

IEventHandlerValue

null

Describes an event handler.

2

IObjectWrapper

IobjectFactory

The central interface of Spring.NET’s low-level object infrastructure.

Typically not directly used by application code but rather implicitly[间接地] via an Spring.Objects.Factory.IobjectFactory.

Implementing classes have the ability to get and set property values (individually or in bulk), get property descriptors and query the readability and writability of properties.

This interface supports nested properties enabling the setting of properties on subproperties to an unlimited depth.

If a property update causes an exception, a Spring.Core.PropertyAccessException will be thrown. Bulk updates continue after exceptions are encountered, throwing an exception wrapping all exceptions encountered during the update.

IobjectWrapper implementations can be used repeatedly, with their “target” or wrapped object changed.

3

IPropertyValues

Ienumerable

PropertyValue[3.1]

A collection style container for PropertyValue instances.

3.1

PropertyValue

 

Holds information and value for an individual property.

Using an object here, rather than just storing all properties in a map keyed by property name, allows for more flexibility, and the ability to handle indexed properties in a special way if necessary.

Note that the value doesn’t need to be the final required Type: an Spring.Objects.IobjectWrapper implementation must handle any necessary conversion, as this object doesn’t know anything about the objects it will be applied to.

4

ISharedStateAware

 

This interface should be implemented by classes that want to have access to the shared state.

Shared state is very useful if you have data that needs to be shared by all instances of e.g. the same webform (or other IHttpHandlers).

 

For example, Spring.Web.UI.Page class implements this interface, which allows each page derived from it to cache localizalization resources and parsed data binding expressions only once and then reuse the cached values, regardless of how many instances of the page are created.

 

5

ISharedStateFactory

 

Abstracts the state sharing strategy used by SharedStateAwareProcessor

2.   Spring.Objects.Factory Namespace

The core namespace implementing Spring.NET's lightweight Inversion of Control (IoC) container.            
Provides an alternative to the Singleton and Prototype design patterns, including a consistent approach to configuration management. Builds on top of the classes defined in the Spring.Objects namespace.

num

interface

Reference & relation

description

1

IFactoryObject

null

Interface to be implemented by objects used within an Spring.Objects.Factory.IObjectFactory that are themselves factories.

If an object implements this interface, it is used as a factory, not directly as an object. IFactoryObjects can support singletons and prototypes (IsSingleton)... please note that an IFactoryObject itself can only ever be a singleton. It is a logic error to configure an IFactoryObject itself to be a prototype.

An object that implements this interface cannot be used as a normal object.

2

IGenericObjectFactory

 

Interface defining a factory which can return an object instance (possibly shared or independent) when invoked.

This interface is typically used to encapsulate a generic factory [泛型工厂] which returns a new instance (prototype) on each invocation. It is similar to the Spring.Objects.Factory.IFactoryObject, but implementations of the aforementioned interface are normally meant to be defined as instances by the user in an Spring.Objects.Factory.IObjectFactory, while implementations of this class are normally meant to be fed as a property to other objects; as such, the GetObject method has different exception handling behavior. 

3

IHierarchicalObjectFactory

IObjectFactory

Sub-interface implemented by object factories that can be part of a hierarchy.

4

IInitializingObject

 

Defines a simple initialization callback for objects that need to some post-initialization logic[后初始化逻辑] after all of their dependencies have been injected.

An implementation of the Spring.Objects.Factory.IinitializingObject.AfterPropertiesSet method might perform some additional custom initialization (over and above that performed by the constructor), or merely check that all mandatory properties have been set (this last example is a very typical use case of this interface).

The use of the IInitializingObject interface by non-Spring.NET framework code can be avoided (and is generally discouraged). The Spring.NET container provides support for a generic initialization method given to the object definition in the object configuration store (be it XML, or a database, etc). This requires slightly more configuration (one attribute-value pair in the case of XML configuration), but removes any dependency on Spring.NET from the class definition.

5

IListableObjectFactory

IObjectFactory

Extension of the Spring.Objects.Factory.IObjectFactory interface to be implemented by object factories that can enumerate[枚举] all their object instances, rather than attempting object lookup by name one by one as requested by clients.

6

IObjectFactory

null

The root interface for accessing a Spring.NET IoC container.

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 Objects 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.

7

IObjectFactoryAware

null

Interface to be implemented by objects that wish to be aware of their owning Spring.Objects.Factory.IObjectFactory.

For example, objects can look up collaborating objects via the factory.

Note that most objects will choose to receive references to collaborating objects via respective properties and / or an appropriate[合适的,适当的] constructor.

For a list of all object lifecycle methods, see the Spring.Objects.Factory.IObjectFactory API documentation.

8

IObjectNameAware

null

Interface to be implemented by objects that wish to be aware of their object name in an Spring.Objects.Factory.IObjectFactory.

Note that most objects will choose to receive references to collaborating objects via respective properties[各自的属性].

For a list of all object lifecycle methods, see the Spring.Objects.Factory.IObjectFactory API documentation.

3.   Spring.Objects.Factory.Config Namespace

Configuration-related convenience classes for object factories.

num

interface

Reference & relation

description

1

IAutowireCapableObjectFactory

null

Extension of the Spring.Objects.Factory.IObjectFactory interface to be implemented by object factories that are capable of autowiring [自动装配] and expose this functionality for existing object instances.

2

IConfigurableFactoryObject

IFactoryObject

Extension of the Spring.Objects.Factory.IFactoryObject interface that injects dependencies into the object managed by the factory [通过工厂向对象注入依赖].

3

IConfigurableListableObjectFactory

l     IAutowireCapableObjectFactory

l     IConfigurableObjectFactory

l     ISingletonObjectRegistry

l     IHierarchicalObjectFactory

l     IListableObjectFactory

l     IObjectFactory

SPI interface to be implemented by most if not all listable object factories.

Allows for framework-internal plug'n'play, e.g. in AbstractApplicationContext.

4

IConfigurableObjectFactory

l     ISingletonObjectRegistry

l     IHierarchicalObjectFactory

l     IObjectFactory

Configuration interface to be implemented by most if not all object factories.

Provides the means[方法] to configure an object factory in addition to the object factory client methods in the Spring.Objects.Factory.IObjectFactory interface.

Allows for framework-internal plug'n'play even when needing access to object factory configuration methods.

When disposed, it will destroy all cached singletons in this factory. Call Dispose when you want to shutdown the factory.

5

IDestructionAwareObjectPostProcessor

l     IObjectPostProcessor

Subinterface [子接口] of Spring.Objects.Factory.Config.IObjectPostProcessor that adds a before-destruction callback.

The typical usage will be to invoke custom destruction callbacks on specific object types, matching corresponding initialization callbacks.

6

IInstantiationAwareObjectPostProcessor

l     IObjectPostProcessor

Subinterface of Spring.Objects.Factory.Config.IObjectPostProcessor that adds a before-instantiation callback.

Typical use cases might include being used to suppress the default instantiation of specific target objects, perhaps in favour of creating proxies with special Spring.Aop.ITargetSources (pooling targets, lazily initializing targets, etc).

7

IObjectPostProcessor

null

Allows for custom modification [自定义修改] of new object instances, e.g. checking for marker interfaces or wrapping them with proxies.

Application contexts can auto-detect [自动侦测] IObjectPostProcessor objects in their object definitions and apply them before any other objects get created. Plain object factories allow for programmatic registration of post-processors.

Typically, post-processors that populate objects via marker interfaces or the like will implement IObjectPostProcessor.PostProcessBeforeInitialization, and post-processors that wrap objects with proxies will normally implement IObjectPostProcessor.PostProcessAfterInitialization.

8

IObjectFactoryPostProcessor

 

Allows for custom modification of an application context's object definitions, adapting the object property values of the context's underlying object factory.

Application contexts can auto-detect IObjectFactoryPostProcessor objects in their object definitions and apply them before any other objects get created.

Useful for custom config files targeted at system administrators that override object properties configured in the application context.

See PropertyResourceConfigurer and its concrete implementations for out-of-the-box solutions that address such configuration needs.

9

IObjectDefinition

null

Describes an object instance, which has property values, constructor argument values, and further information supplied by concrete implementations.

This is just a minimal interface[最小接口]: the main intention[目的] is to allow Spring.Objects.Factory.Config.IObjectFactoryPostProcessor (like PropertyPlaceholderConfigurer) to access and modify property values.

10

ISingletonObjectRegistry

 

Interface that defines a registry for shared object instances.

Can be implemented by Spring.Objects.Factory.IObjectFactory implementations in order to expose their singleton management facility in a uniform manner[统一的方式].

The Spring.Objects.Factory.Config.IConfigurableObjectFactory interface extends this interface.

11

IVariableSource[变量源]

null

Defines contract[规定] that different variable sources have to implement.

The "variable sources" are objects containing name-value pairs that allow a variable value to be retrieved for the given name[通过名称检索值].

Out of the box, Spring.NET supports a number of variable sources, that allow users to obtain variable values from .NET config files, Java-style property files, environment, registry, etc.

Users can always write their own variable sources implementations, that will allow them to load variable values from the database or other proprietary data source[用户可以提供自己的实现].

12

SmartInstantiationAwareObjectPostProcessor

l     IInstantiationAwareObjectPostProcessor

l     IObjectPostProcessor

Extension of the IInstantiationAwareObjectPostProcessor interface, adding a callback for predicting the eventual[最终的] type of a processed object.

This interface is a special purpose interface, mainly for internal use within the framework. In general, application-provided post-processors should simply implement the plain Spring.Objects.Factory.Config.IObjectPostProcessor interface or derive from the InstantiationAwareObjectPostProcessorAdapter class. New methods might be added to this interface even in point releases.

4. Spring.Objects.Factory.Support Namespace

Classes supporting the classes defined in the Spring.Objects.Factory namespace.

Contains a number of abstract base classes for custom IObjectFactory implementations.    [support:支持]

num

interface

Reference & relation

description

1

IAutowireCandidateResolver

null

Strategy interface for determining whether a specific object definition qualifies as an autowire[自动装配] candidate for a specific dependency.

2

IConfigurableObjectDefinition

IObjectDefinition

Describes a configurable object instance, which has property values, constructor argument values, and further information supplied by concrete implementations.

3

IInstantiationStrategy

null

Responsible for creating instances corresponding to a Spring.Objects.Factory.Support.RootObjectDefinition.

4

IManagedCollection

 

Denotes a special placeholder collection that may contain RuntimeObjectReferences or other placeholder objects that will need to be resolved.

'A special placeholder collection' means that the elements of this collection can be placeholders for objects that will be resolved later by a Spring.NET IoC container, i.e. the elements themselves will be resolved at runtime by the enclosing IoC container.

The core Spring.NET library already provides three implementations of this interface straight out of the box; they are...

l     ManagedList.

l     ManagedDictionary.

l     ManagedSet.

If you have a custom collection class (i.e. a class that either implements the ICollection directly or derives from a class that does) that you would like to expose as a special placeholder collection (i.e. one that can have RuntimeObjectReferences as elements that will be resolved at runtime by an appropriate Spring.NET IoC container, just implement this interface.

5

IMethodReplacer

null

Permits the (re)implementation of an arbitrary method on a Spring.NET IoC container managed object.

Encapsulates the notion of the Method-Injection form of Dependency Injection.

Methods that are dependency injected with implementations of this interface may be (but need not be) , in which case the container will create a concrete subclass of the class prior to[之前的] instantiation.

Do not use this mechanism as a means of AOP. See the reference manual for examples of appropriate usages of this interface.

6

IObjectDefinitionFactory

null

Central interface for factories that can create IConfigurableObjectDefinition instances.

Allows for replaceable object definition factories using the Strategy pattern.

7

IObjectDefinitionReader

null

Simple interface for object definition readers.

8

IObjectDefinitionRegistry

null

Interface for registries that hold object definitions, i.e. Spring.Objects.Factory.Support.RootObjectDefinition and Spring.Objects.Factory.Support.ChildObjectDefinition instances.

Typically implemented by object factories that work with the AbstractObjectDefinition hierarchy internally.

9

IObjectNameGenerator

null

Strategy interface for generating object names for object definitions

5.   Spring.Objects.Factory.Xml Namespace

Contains an abstract XML-based IObjectFactory implementation, including an XML Schema for validation.

num

interface

Reference & relation

description

1

INamespaceParser

null

Strategy interface for parsing XML object definitions.

Used by DefaultObjectDefinitionDocumentReader for actually parsing a DOM document or XmlElement fragment.

2

IObjectDefinitionDocumentReader

 

SPI for parsing an XML document that contains Spring object definitions. Used by Spring.Objects.Factory.Xml.XmlObjectDefinitionReader for actually parsing a DOM document.

Instantiated[实例化] per document to parse: Implementations can hold state in instance variables during the execution of the RegisterObjectDefinitions method, for example global settings that are defined for all object definitions in the document.

3

IObjectDefinitionParser

 

Interface used to handle custom, top-level tags.

Implementations are free to turn the metadata in the custom tag into as many Spring.Objects.Factory.Config.IObjectDefinition as required.

6.   Spring.Objects.Support Namespace

Classes supporting the classes defined in the Spring.Objects.Factory namespace.

num

interface

Reference & relation

description

1

ISortDefinition

null

Definition for sorting object instances by a property.

7. Spring.Objects.Events Namespace

Note: Interfaces that define a loosely coupled event model.

num

interface

Reference & relation

description

1

IEventRegistry

null

A registry that manages subscriptions to and the publishing of events.

2

IEventRegistryAware

null

To be implemented by any object that wishes to receive a reference to an Spring.Objects.Events.IEventRegistry.

This interface only applies to objects that have been instantiated [实例化] within the context of an IApplicationContext. This interface does not typically need to be implemented by application code, but is rather used by classes internal to Spring.NET.

 

8. Spring.Objects.Events.Support NameSpace : Support classes for the interfaces defined in the Spring.Objects.Events namespace, such as an implementation of the IEventRegistry interface.

9. Spring.Objects.Factory.Attributes NameSpace : Required attribute and corresponding object factory post processor.

10. Spring.Objects.Factory.Parsing NameSpace : Helper classes used when parsing XML configuration files

posted on 2009-03-17 15:09  wbgu  阅读(834)  评论(0编辑  收藏  举报