The Spring.NET Framework

The Spring.NET Framework

The Spring.NET Framework

Reference Documentation

Authors

Mark Pollack , Rick Evans , Aleksandar Seovic , Bruno Baia , Federico Spinazzi , Rob Harrop , Griffin Caprio , Ruben Bartelink , Choy Rim , The Spring Java Team

Version 1.2.0

Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.

Last Updated Novermber 10, 2008 (Latest documentation)


1. Preface
2. Introduction
2.1. Overview
2.2. Background
2.3. Modules
2.4. Usage Scenarios
2.5. Quickstart applications
2.6. License Information
2.7. Support
3. Background information
3.1. Inversion of Control
4. Migrating from 1.1 M2
4.1. Introduction
4.2. Important Changes
4.2.1. Namespaces
4.2.2. Core
4.2.3. Web
4.2.4. Data
I. Core Technologies
5. The IoC container
5.1. Introduction
5.2. Basics - containers and objects
5.2.1. The container
5.2.1.1. Configuration metadata
5.2.2. Instantiating a container
5.2.2.1. Composing XML-based configuration metadata
5.2.3. The Objects
5.2.3.1. Naming objects
5.2.4. Object creation
5.2.4.1. Object creation via constructor invocation
5.2.4.2. Object creation via a static factory method
5.2.4.3. Object creation via an instance factory method
5.2.5. Object creation of generic types
5.2.5.1. Object creation of generic types via constructor invocation
5.2.5.2. Object creation of generic types via static factory method
5.2.5.3. Object creation of generic types via instance factory method
5.2.6. Using the container
5.3. Dependencies
5.3.1. Injecting dependencies
5.3.1.1. Constructor Injection
5.3.1.2. Setter Injection
5.3.1.3. Some examples
5.3.2. Dependencies and configuration in detail
5.3.2.1. Straight values (primitives, strings, etc.)
5.3.2.2. Referring to collaborating objects
5.3.2.3. Inline objects
5.3.2.4. Setting collection values
5.3.2.5. Setting generic collection values
5.3.2.6. Setting null values
5.3.2.7. Setting indexer properties
5.3.2.8. Value and ref shortcut forms
5.3.2.9. Compound property names and Spring expression references
5.3.3. Declarative Event Listener Registration
5.3.3.1. Declarative event handlers
5.3.3.2. Configuring a method to be invoked when an event is fired
5.3.3.3. Registering a collection of handler methods based on a regular expression
5.3.3.4. Registering a handler method against an event name that contains a regular expression
5.3.4. Using depends-on
5.3.5. Lazily-instantiated objects
5.3.6. Autowiring collaborators
5.3.7. Checking for dependencies
5.3.8. Method Injection
5.3.8.1. Lookup Method Injection
5.3.8.2. Arbitrary method replacement
5.3.9. Setting a reference using the members of other objects and classes.
5.3.9.1. Setting a reference to the value of property.
5.3.9.2. Setting a reference to the value of field.
5.3.9.3. Setting a property or constructor argument to the return value of a method invocation.
5.3.10. Provided IFactoryObject implementations
5.3.10.1. Common logging
5.4. Object Scopes
5.4.1. The singleton scope
5.4.2. The prototype scope
5.4.3. Singleton objecgts with prototype-object dependencies
5.4.4. The other scopes
5.5. Type conversion
5.5.1. Type Conversion for Enumerations
5.5.2. Built-in TypeConverters
5.5.3. Custom Type Conversion
5.5.3.1. Using CustomConverterConfigurer
5.6. Customizing the nature of an object
5.6.1. Lifecycle interfaces
5.6.1.1. IInitializingObject / init-method
5.6.1.2. IDisposable / destroy-method
5.6.2. Knowing who you are
5.6.2.1. IObjectFactoryAware
5.6.2.2. IObjectNameAware
5.7. Object definition inheritance
5.8. Interacting with the container
5.8.1. Obtaining an IFactoryObject, not its product
5.9. Container extension points
5.9.1. Customizing objects with IObjectPostProcessors
5.9.1.1. Example: Hello World, IObjectPostProcessor-style
5.9.1.2. Example: the RequiredAttributeObjectPostProcessor
5.9.2. Customizing configuration metadata with ObjectFactoryPostProcessors
5.9.2.1. Example: The PropertyPlaceholderConfigurer
5.9.2.2. Example: The PropertyOverrideConfigurer
5.9.2.3. IVariableSource
5.9.3. Customizing instantiation logic using IFactoryObjects
5.9.3.1. IConfigurableFactoryObject
5.10. The IApplicationContext
5.10.1. IObjectFactory or IApplicationContext?
5.11. Configuration of IApplicationContext
5.11.1. Registering custom parsers
5.11.2. Registering custom resource handlers
5.11.3. Registering Type Aliases
5.11.4. Registering Type Converters
5.12. Added functionality of the IApplicationContext
5.12.1. Context Hierarchies
5.12.2. Using IMessageSource
5.12.3. Using resources within Spring.NET
5.12.4. Loosely coupled events
5.12.5. Event notification from IApplicationContext
5.13. Customized behavior in the ApplicationContext
5.13.1. The IApplicationContextAware marker interface
5.13.2. The IObjectPostProcessor
5.13.3. The IObjectFactoryPostProcessor
5.13.4. The PropertyPlaceholderConfigurer
5.14. Configuration of ApplicationContext without using XML
5.15. Service Locator access
5.16. Stereotype attributes
6. The IObjectWrapper and Type conversion
6.1. Introduction
6.2. Manipulating objects using the IObjectWrapper
6.2.1. Setting and getting basic and nested properties
6.2.2. Other features worth mentioning
6.3. Type conversion
6.3.1. Type Conversion for Enumerations
6.4. Built-in TypeConverters
6.4.1. Custom type converters
7. Resources
7.1. Introduction
7.2. The IResource interface
7.3. Built-in IResource implementations
7.3.1. Registering custom IResource implementations
7.4. The IResourceLoader
7.5. The IResourceLoaderAware interface
7.6. Application contexts and IResource paths
8. Threading and Concurrency Support
8.1. Introduction
8.2. Thread Local Storage
8.3. Synchronization Primitives
8.3.1. ISync
8.3.2. SyncHolder
8.3.3. Latch
8.3.4. Semaphore
9. Object Pooling
9.1. Introduction
9.2. Interfaces and Implementations
10. Spring.NET miscellanea
10.1. Introduction
10.2. PathMatcher
10.2.1. General rules
10.2.2. Matching filenames
10.2.3. Matching subdirectories
10.2.4. Case does matter, slashes don't
11. Expression Evaluation
11.1. Introduction
11.2. Evaluating Expressions
11.3. Language Reference
11.3.1. Literal expressions
11.3.2. Properties, Arrays, Lists, Dictionaries, Indexers
11.3.2.1. Defining Arrays, Lists and Dictionaries Inline
11.3.3. Methods
11.3.4. Operators
11.3.4.1. Relational operators
11.3.4.2. Logical operators
11.3.4.3. Mathematical operators
11.3.5. Assignment
11.3.6. Expression lists
11.3.7. Types
11.3.8. Type Registration
11.3.9. Constructors
11.3.10. Variables
11.3.10.1. The '#this' and '#root' variables
11.3.11. Ternary Operator (If-Then-Else)
11.3.12. List Projection and Selection
11.3.13. Collection Processors and Aggregators
11.3.13.1. Count Aggregator
11.3.13.2. Sum Aggregator
11.3.13.3. Average Aggregator
11.3.13.4. Minimum Aggregator
11.3.13.5. Maximum Aggregator
11.3.13.6. Non-null Processor
11.3.13.7. Distinct Processor
11.3.13.8. Sort Processor
11.3.13.9. Type Conversion Processor
11.3.13.10. Reverse Processor
11.3.13.11. OrderBy Processor
11.3.13.12. User Defined Collection Processor
11.3.14. Spring Object References
11.3.15. Lambda Expressions
11.3.16. Delegate Expressions
11.3.17. Null Context
11.4. Classes used in the examples
12. Validation Framework
12.1. Introduction
12.2. Example Usage
12.3. Validator Groups
12.4. Validators
12.4.1. Condition Validator
12.4.2. Required Validator
12.4.3. Regular Expression Validator
12.4.4. Generic Validator
12.4.5. Conditional Validator Execution
12.5. Validator Actions
12.5.1. Error Message Action
12.5.2. Generic Actions
12.6. Validator References
12.7. Progammatic usage
12.8. Usage tips within ASP.NET
12.8.1. Rendering Validation Errors
12.8.1.1. Configuring which Error Renderer to use.
13. Aspect Oriented Programming with Spring.NET
13.1. Introduction
13.1.1. AOP concepts
13.1.2. Spring.NET AOP capabilities
13.1.3. AOP Proxies in Spring.NET
13.2. Pointcut API in Spring.NET
13.2.1. Concepts
13.2.2. Operations on pointcuts
13.2.3. Convenience pointcut implementations
13.2.3.1. Static pointcuts
13.2.3.2. Dynamic Pointcuts
13.2.4. Custom pointcuts
13.3. Advice API in Spring.NET
13.3.1. Advice Lifecycle
13.3.2. Advice types
13.3.2.1. Interception Around Advice
13.3.2.2. Before advice
13.3.2.3. Throws advice
13.3.2.4. After Returning advice
13.3.2.5. Advice Ordering
13.3.2.6. Introduction advice
13.4. Advisor API in Spring.NET
13.5. Using the ProxyFactoryObject to create AOP proxies
13.5.1. Basics
13.5.2. ProxyFactoryObject Properties
13.5.3. Proxying Interfaces
13.5.4. Proxying Classes
13.5.5. Concise proxy definitions
13.6. Proxying mechanisms
13.6.1. InheritanceBasedAopConfigurer
13.7. Creating AOP Proxies Programatically with the ProxyFactory
13.8. Manipulating Advised Objects
13.9. Using the "autoproxy" facility
13.9.1. Autoproxy object definitions
13.9.1.1. ObjectNameAutoProxyCreator
13.9.1.2. DefaultAdvisorAutoProxyCreator
13.9.1.3. PointcutFilteringAutoProxyCreator
13.9.1.4. TypeNameAutoProxyCreator
13.9.1.5. AttributeAutoProxyCreator
13.9.1.6. AbstractFilteringAutoProxyCreator
13.9.1.7. AbstractAutoProxyCreator
13.9.2. Using attribute-driven auto-proxying
13.10. Using AOP Namespace
13.11. Using TargetSources
13.11.1. Hot swappable target sources
13.11.2. Pooling target sources
13.11.3. Prototype target sources
13.11.4. ThreadLocal target sources
13.12. Defining new Advice types
13.13. Further reading and resources
14. Aspect Library
14.1. Introduction
14.2. Caching
14.3. Exception Handling
14.3.1. Language Reference
14.4. Logging
14.5. Retry
14.5.1. Language Reference
14.6. Transactions
14.7. Parameter Validation
15. Common Logging
15.1. Introduction
16. Testing
16.1. Introduction
16.2. Unit testing
16.3. Integration testing
16.3.1. Context management and caching
16.3.2. Dependency Injection of test fixtures
16.3.2.1. Field level injection
16.3.3. Transaction management
16.3.4. Convenience variables
16.3.5.
16.4. Further Resources
II. Middle Tier Data Access
17. Transaction management
17.1. Introduction
17.2. Motivations
17.3. Key Abstractions
17.4. Resource synchronization with transactions
17.4.1. High-level approach
17.4.2. Low-level approach
17.5. Declarative transaction management
17.5.1. Understanding Spring's declarative transaction implementation
17.5.2. A First Example
17.5.3. Declarative transactions using the transaction namespace
17.5.4. Transaction attribute settings
17.5.5. Declarative Transactions using AutoProxy
17.5.5.1. Creating transactional proxies with ObjectNameAutoProxyCreator
17.5.5.2. Creating transactional proxies with DefaultAdvisorAutoProxyCreator
17.5.6. Declarative Transactions using TransactionProxyFactoryObject
17.5.7. Concise proxy definitions
17.5.8. Declarative Transactions using ProxyFactoryObject
17.6. Programmatic transaction management
17.6.1. Using the TransactionTemplate
17.6.1.1. Specifying transaction settings
17.6.2. Using the PlatformTransactionManager
17.7. Choosing between programmatic and declarative transaction management
17.8. Transaction lifecycle and status information
18. DAO support
18.1. Introduction
18.2. Consistent exception hierarchy
18.3. Consistent abstract classes for DAO support
19. DbProvider
19.1. Introduction
19.2. IDbProvider and DbProviderFactory
19.3. XML based configuration
19.4. Connection String management
19.5. Additional IDbProvider implementations
19.5.1. UserCredentialsDbProvider
19.5.2. MultiDelegatingDbProvider
20. Data access using ADO.NET
20.1. Introduction
Motivations
20.3. Provider Abstraction
20.3.1. Creating an instance of IDbProvider
20.4. Namespaces
20.5. Approaches to Data Access
20.6. Introduction to AdoTemplate
20.6.1. Execute Callback
20.6.2. Execute Callback in .NET 2.0
20.6.3. Execute Callback in .NET 1.1
20.6.4. Quick Guide to AdoTemplate Methods
20.6.5. Quick Guide to AdoTemplate Properties
20.7. Transaction Management
20.8. Exception Translation
20.9. Parameter Management
20.9.1. IDbParametersBuilder
20.9.2. IDbParameters
20.10. Custom IDataReader implementations
20.11. Basic data access operations
20.11.1. ExecuteNonQuery
20.11.2. ExecuteScalar
20.12. Queries and Lightweight Object Mapping
20.12.1. ResultSetExtractor
20.12.2. RowCallback
20.12.3. RowMapper
20.12.4. Query for a single object
20.12.5. Query using a CommandCreator
20.13. DataTable and DataSet
20.13.1. DataTables
20.13.2. DataSets
20.14. TableAdapters and participation in transactional context
20.15. Database operations as Objects
20.15.1. AdoQuery
20.15.2. MappingAdoQuery
20.15.3. AdoNonQuery
20.15.4. Stored Procedure
21. Object Relational Mapping (ORM) data access
21.1. Introduction
21.2. NHibernate
21.2.1. Resource management
21.2.2. Transaction Management
21.2.3. SessionFactory set up in a Spring container
21.2.4. The HibernateTemplate
21.2.5. Implementing Spring-based DAOs without callbacks
21.2.6. Implementing DAOs based on plain Hibernate 1.2/2.0 API
21.2.6.1. Exception Translation
21.2.7. Programmatic transaction demarcation
21.2.8. Declarative transaction demarcation
21.2.9. Transaction management strategies
21.2.10. Web Session Management
21.2.11. Session Scope
III. The Web
22. Spring.NET Web Framework
22.1. Introduction
22.2. Background
22.3. Automatic context loading and hierarchical contexts
22.3.1. Configuration
22.3.1.1. Configuration for IIS7
22.3.2. Context Hierarchy
22.4. Dependency Injection for ASP.NET Pages
22.4.1. Injecting Dependencies into Controls
22.4.2. Injecting dependencies into custom HTTP modules
22.4.3. Injecting dependencies into HTTP handlers and handler factories
22.4.4. Injecting dependencies into custom providers
22.4.5. Customizing control dependency injection
22.5. Web object scopes
22.6. Master Pages in ASP.NET 1.1
22.6.1. Linking child pages to their master
22.7. Bidirectional Data Binding and Model Management
22.7.1. Data Binding Under the Hood
22.7.1.1. Binding Direction
22.7.1.2. Formatters
22.7.1.3. Type Conversion
22.7.1.4. Data Binding Events
22.7.1.5. Rendering Binding Errors
22.7.1.6. HttpRequestListBindingContainer
22.7.2. Using DataBindingPanel
22.7.3. Customizing Model Persistence
22.8. Localization and Message Sources
22.8.1. Automatic Localization Using Localizers ("Push" Localization)
22.8.2. Global Message Sources
22.8.3. Working with Localizers
22.8.4. Applying Resources Manually ("Pull" Localization)
22.8.5. Localizing Images within a Web Application
22.8.6. User Culture Management
22.8.6.1. DefaultWebCultureResolver
22.8.6.2. RequestCultureResolver
22.8.6.3. SessionCultureResolver
22.8.6.4. CookieCultureResolver
22.8.7. Changing Cultures
22.9. Result Mapping
22.9.1. Registering user defined transfer modes
22.10. Client-Side Scripting
22.10.1. Registering Scripts within the head HTML section
22.10.2. Adding CSS Definitions to the head Section
22.10.3. Well-Known Directories
22.11. Spring User Controls
22.11.1. Validation Controls
22.11.2. Databinding Controls
22.11.3. Calendar Control
22.11.4. Panel Control
23. ASP.NET AJAX
23.1. Introduction
23.2. Web Services
23.2.1. Exposing Web Services
23.2.2. Calling Web Services by using JavaScript
IV. Services
24. Introduction to Spring Services
24.1. Introduction
25. .NET Remoting
25.1. Introduction
25.2. Publishing SAOs on the Server
25.2.1. SAO Singleton
25.2.2. SAO SingleCall
25.2.3. IIS Application Configuration
25.3. Accessing a SAO on the Client
25.4. CAO best practices
25.5. Registering a CAO object on the Server
25.5.1. Applying AOP advice to exported CAO objects
25.6. Accessing a CAO on the Client
25.6.1. Applying AOP advice to client side CAO objects.
25.7. XML Schema for configuration
25.8. Additional Resources
26. .NET Enterprise Services
26.1. Introduction
26.2. Serviced Components
26.3. Server Side
26.4. Client Side
27. Web Services
27.1. Introduction
27.2. Server-side
27.2.1. Removing the need for .asmx files
27.2.2. Injecting dependencies into web services
27.2.3. Exposing PONOs as Web Services
27.2.4. Exporting an AOP Proxy as a Web Service
27.3. Client-side
27.3.1. Using VS.NET generated proxy
27.3.2. Generating proxies dynamically
27.3.3. Configuring the proxy instance
28. Windows Communication Foundation (WCF)
28.1. Introduction
28.2. Configuring WCF services via Dependency Injection
28.2.1. Dependency Injection
28.3. Apply AOP advice to WCF services
28.4. Creating client side proxies declaratively
28.5. Exporting PONOs as WCF Services
V. Integration
29. Message Oriented Middleware - Apache ActiveMQ
29.1. Introduction
29.1.1. Separation of Concerns
29.1.2. Interoperability and provider portability
29.1.3. The role of Messaging API in a 'WCF world'
29.2. Using Spring Messaging
29.2.1. Messaging Template overview
29.2.2. Connections
29.2.3. Caching Messaging Resources
29.2.3.1. SingleConnectionFactory
29.2.3.2. CachingConnectionFactory
29.2.4. Destination Management
29.2.5. Message Listener Containers
29.2.6. Transaction Management
29.3. Sending a Message
29.3.1. Using MessageConverters
29.4. Session and Producer Callback
29.5. Receiving a message
29.5.1. Synchronous Reception
29.5.2. Asynchronous Reception
29.5.3. The ISessionAwareMessageListener interface
29.5.4. MessageListenerAdapater
29.5.5. Processing messages within a messaging transaction
29.5.6. Messaging Namespace support
30. Message Oriented Middleware - MSMQ
30.1. Introduction
30.2. A quick tour for the impatient
30.3. Using Spring MSMQ
30.3.1. MessageQueueTemplate
30.3.2. MessageQueueFactoryObject
30.3.3. MessageQueue and IMessageConverter resource management
30.3.4. Message Listener Containers
30.3.4.1. NonTransactionalMessageListenerContainer
30.3.4.2. TransactionalMessageListenerContainer
30.3.4.3. DistributedTxMessageListenerContainer
30.4. MessageConverters
30.4.1. Using MessageConverters
30.5. Interface based message processing
30.5.1.
30.5.1.1. MessageListenerAdapater
30.6. Comparison with using WCF
31. Scheduling and Thread Pooling
31.1. Introduction
31.2. Using the Quartz.NET Scheduler
31.2.1. Using the JobDetailObject
31.2.2. Using the MethodInvokingJobDetailFactoryObject
31.2.3. Wiring up jobs using triggers and the SchedulerFactoryObject
VI. VS.NET Integration
32. Visual Studio.NET Integration
32.1. XML Editing and Validation
32.2. Versions of XML Schema
32.3. Integrated API help
VII. Quickstart applications
33. IoC Quickstarts
33.1. Introduction
33.2. Movie Finder
33.2.1. Getting Started - Movie Finder
33.2.2. First Object Definition
33.2.3. Setter Injection
33.2.4. Constructor Injection
33.2.5. Summary
33.2.6. Logging
33.3. ApplicationContext and IMessageSource
33.3.1. Introduction
33.4. ApplicationContext and IEventRegistry
33.4.1. Introduction
33.5. Pooling example
33.5.1. Implementing Spring.Pool.IPoolableObjectFactory
33.5.2. Being smart using pooled objects
33.5.3. Using the executor to do a parallel grep
33.6. AOP
34. AOP Guide
34.1. Introduction
34.2. The basics
34.2.1. Applying advice
34.2.2. Using Pointcuts - the basics
34.3. Going deeper
34.3.1. Other types of Advice
34.3.1.1. Before advice
34.3.1.2. After advice
34.3.1.3. Throws advice
34.3.1.4. Introductions (mixins)
34.3.1.5. Layering advice
34.3.1.6. Configuring advice
34.3.2. Using Attributes to define Pointcuts
34.4. The Spring.NET AOP Cookbook
34.4.1. Caching
34.4.2. Performance Monitoring
34.4.3. Retry Rules
34.5. Spring.NET AOP Best Practices
35. Portable Service Abstraction Quick Start
35.1. Introduction
35.2. .NET Remoting Example
35.3. Implementation
35.4. Running the application
35.5. Remoting Schema
35.6. .NET Enterprise Services Example
35.7. Web Services Example
35.8. Additional Resources
36. Web Quickstarts
36.1. Introduction
37. SpringAir - Reference Application
37.1. Introduction
37.2. Getting Started
37.3. Container configuration
37.4. Bi-directional data binding
37.5. Declarative Validation
37.6. Internationalization
37.7. Web Services
38. Data Access QuickStart
38.1. Introduction
38.1.1. Database configuration
38.1.1.1. AdoTemplate Configuration
38.1.2. CommandCallback
39. Transactions QuickStart
39.1. Introduction
39.2. Application Overview
39.2.1. Interfaces
39.3. Implementation
39.4. Configuration
39.4.1. Rollback Rules
39.5. Adding additional Aspects
40. NHibernate QuickStart
40.1. Introduction
41. Quartz QuickStart
41.1. Introduction
41.2. Application Overview
41.3. Standard job scheduling
41.4. Scheduling arbitrary methods as jobs
42. NMS QuickStart
42.1. Introduction
42.2. Message Destinations
42.3. Gateways
42.4. Message Data
42.5. Message Handlers
42.6. Message Converters
42.7. Messaging Infrastructure
42.8. Running the application
43. MSMQ QuickStart
43.1. Introduction
43.2. Message Destinations
43.3. Gateways
43.4. Message Data
43.5. Message Handlers
43.6. MessageConverters
43.7. Messaging Infrastructure
43.8. Running the application
44. WCF QuickStart
44.1. Introduction
44.2. The server side
44.2.1. WCF Dependency Injection and AOP in self-hosted application
44.2.2. WCF Dependency Injection and AOP in IIS web application
44.3. Client access
VIII. Spring.NET for Java developers
45. Spring.NET for Java Developers
45.1. Introduction
45.2. Beans to Objects
45.3. PropertyEditors to TypeConverters
45.4. ResourceBundle-ResourceManager
45.5. Exceptions
45.6. Application Configuration
45.7. AOP Framework
45.7.1. Cannot specify target name at the end of interceptorNames for ProxyFactoryObject
A. XML Schema-based configuration
A.1. Introduction
A.2. XML Schema-based configuration
A.2.1. Referencing the schemas
A.2.2. The tx (transaction) schema
A.2.3. The aop schema
A.2.4. The db schema
A.2.5. The remoting schema
A.2.6. The nms messaging schema
A.2.7. The validation schema
A.2.8. The objects schema
A.3. Setting up your IDE
B. Extensible XML authoring
B.1. Introduction
B.2. Authoring the schema
B.3. Coding a INamespaceParser
B.4. Coding an IObjectDefinitionParser
B.5. Registering the handler and the schema
B.5.1. NamespaceParsersSectionHandler
B.6. Using a custom extension in your Spring XML configuration
B.7. Further Resources
C. Spring.NET's spring-objects.xsd