The Spring.NET Framework Reference Manual.pdf

(3822 KB) Pobierz
Reference Documentation
Version 1.3.2
Last Updated August 1, 2011 (Latest documentation)
Copyright © 2004-2008 Mark Pollack, Rick Evans, Aleksandar Seovic, Bruno
Baia, Erich Eichinger, Federico Spinazzi, Rob Harrop, Griffin Caprio, Ruben
Bartelink, Choy Rim, Erez Mazor, Stephen Bohlen, The Spring Java Team
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.
788060839.010.png
1. Preface ................................................................................................................................................ 1
2. Introduction ......................................................................................................................................... 2
2.1. Overview .................................................................................................................................... 2
2.2. Background ................................................................................................................................. 2
2.3. Modules ...................................................................................................................................... 3
2.4. Usage Scenarios .......................................................................................................................... 4
2.5. Quickstart applications ................................................................................................................. 5
2.6. Associated Spring.NET Projects ................................................................................................... 6
2.7. License Information ..................................................................................................................... 6
2.8. Support ....................................................................................................................................... 6
3. Background information ....................................................................................................................... 7
3.1. Inversion of Control .................................................................................................................... 7
4. Migrating from 1.1 M2 ........................................................................................................................ 8
4.1. Introduction ................................................................................................................................. 8
4.2. Important Changes ...................................................................................................................... 8
4.2.1. Namespaces .................................................................................................................. 8
4.2.2. Core ............................................................................................................................. 9
4.2.3. Web ............................................................................................................................. 9
4.2.4. Data ............................................................................................................................. 9
4.3. Support for .NET 4 ...................................................................................................................... 9
I. Core Technologies .............................................................................................................................. 10
5. The IoC container ........................................................................................................................ 11
5.1. Introduction ................................................................................................................... 11
5.2. Container overview ........................................................................................................ 11
5.2.1. Configuration metadata ............................................................................. 12
5.2.2. Instantiating a container ............................................................................ 13
5.2.3. Using the container ................................................................................... 17
5.2.4. Object definition overview ........................................................................ 17
5.2.5. Instantiating objects .................................................................................. 19
5.2.6. Object creation of generic types ................................................................. 21
5.3. Dependencies ................................................................................................................ 23
5.3.1. Dependency injection ................................................................................ 23
5.3.2. Dependencies and configuration in detail .................................................... 30
5.3.3. Declarative Event Listener Registration ...................................................... 39
5.3.4. Using depends-on ..................................................................................... 41
5.3.5. Lazily-initialized objects ............................................................................ 41
5.3.6. Autowiring collaborators ........................................................................... 42
5.3.7. Checking for dependencies ........................................................................ 43
5.3.8. Method injection ....................................................................................... 44
5.3.10. Provided IFactoryObject implementations ................................................. 51
5.4. Object Scopes ............................................................................................................... 51
5.4.1. The singleton scope .................................................................................. 52
5.4.2. The prototype scope .................................................................................. 52
5.4.4. Request, session and web application scopes ............................................... 53
5.5. Type conversion ............................................................................................................ 53
5.5.1. Type Conversion for Enumerations ............................................................ 54
5.5.2. Built-in TypeConverters ............................................................................ 54
Spring Framework (Version 1.3.2)
ii
788060839.011.png 788060839.012.png 788060839.013.png
 
The Spring.NET Framework
5.5.3. Custom Type Conversion .......................................................................... 55
5.6. Customizing the nature of an object ................................................................................ 57
5.6.1. Lifecycle interfaces ................................................................................... 57
5.6.2. IApplicationContextAware and IObjectNameAware .................................... 58
5.7. Object definition inheritance .......................................................................................... 59
5.8. Container extension points ............................................................................................. 60
5.8.1. Obtaining an IFactoryObject, not its product ............................................... 61
5.9. Container extension points ............................................................................................. 61
5.9.1. Customizing objects with IObjectPostProcessors ......................................... 61
5.10. The IApplicationContext .............................................................................................. 72
5.10.1. IObjectFactory or IApplicationContext? .................................................... 73
5.11. Configuration of IApplicationContext ........................................................................... 73
5.11.1. Registering custom parsers ...................................................................... 74
5.11.2. Registering custom resource handlers ....................................................... 75
5.11.3. Registering Type Aliases ......................................................................... 76
5.11.4. Registering Type Converters .................................................................... 77
5.12. Added functionality of the IApplicationContext ............................................................. 77
5.12.1. Context Hierarchies ................................................................................. 77
5.12.2. Using IMessageSource ............................................................................ 78
5.12.3. Using resources within Spring.NET .......................................................... 80
5.12.4. Loosely coupled events ........................................................................... 80
5.12.5. Event notification from IApplicationContext ............................................. 81
5.13. Customized behavior in the ApplicationContext ............................................................. 83
5.13.1. The IApplicationContextAware marker interface ....................................... 83
5.13.2. The IObjectPostProcessor ........................................................................ 83
5.13.3. The IObjectFactoryPostProcessor ............................................................. 83
5.13.4. The PropertyPlaceholderConfigurer .......................................................... 83
5.14. Configuration of ApplicationContext without using XML ............................................... 83
5.15. Service Locator access ................................................................................................. 84
5.16. Stereotype attributes ..................................................................................................... 85
6. The IObjectWrapper and Type conversion ..................................................................................... 86
6.1. Introduction ................................................................................................................... 86
6.2. Manipulating objects using the IObjectWrapper ............................................................... 86
6.2.1. Setting and getting basic and nested properties ............................................ 86
6.2.2. Other features worth mentioning ................................................................ 88
6.3. Type conversion ............................................................................................................ 88
6.3.1. Type Conversion for Enumerations ............................................................ 89
6.4. Built-in TypeConverters ................................................................................................. 89
6.4.1. Custom type converters ............................................................................. 90
7. Resources .................................................................................................................................... 91
7.1. Introduction ................................................................................................................... 91
7.2. The IResource interface ................................................................................................. 91
7.3. Built-in IResource implementations ................................................................................ 92
7.3.1. Registering custom IResource implementations ........................................... 92
7.4. The IResourceLoader ..................................................................................................... 93
7.5. The IResourceLoaderAware interface ............................................................................. 93
7.6. Application contexts and IResource paths ....................................................................... 94
Spring Framework (Version 1.3.2)
iii
788060839.001.png 788060839.002.png 788060839.003.png
 
The Spring.NET Framework
8. Threading and Concurrency Support ............................................................................................. 95
8.1. Introduction ................................................................................................................... 95
8.2. Thread Local Storage ..................................................................................................... 95
8.3. Synchronization Primitives ............................................................................................. 96
8.3.1. ISync ........................................................................................................ 96
8.3.2. SyncHolder ............................................................................................... 96
8.3.3. Latch ........................................................................................................ 97
8.3.4. Semaphore ................................................................................................ 97
9. Object Pooling ............................................................................................................................. 99
9.1. Introduction ................................................................................................................... 99
9.2. Interfaces and Implementations ...................................................................................... 99
10. Spring.NET miscellanea ............................................................................................................ 100
10.1. Introduction ............................................................................................................... 100
10.2. PathMatcher ............................................................................................................... 100
10.2.1. General rules ......................................................................................... 100
10.2.2. Matching filenames ............................................................................... 100
10.2.3. Matching subdirectories ......................................................................... 101
10.2.4. Case does matter, slashes don't ............................................................... 101
11. Expression Evaluation ............................................................................................................... 103
11.1. Introduction ............................................................................................................... 103
11.2. Evaluating Expressions ............................................................................................... 103
11.3. Language Reference ................................................................................................... 104
11.3.1. Literal expressions ................................................................................. 104
11.3.2. Properties, Arrays, Lists, Dictionaries, Indexers ....................................... 105
11.3.3. Methods ................................................................................................ 106
11.3.4. Operators .............................................................................................. 106
11.3.5. Assignment ........................................................................................... 109
11.3.6. Expression lists ..................................................................................... 109
11.3.7. Types .................................................................................................... 109
11.3.8. Type Registration .................................................................................. 110
11.3.9. Constructors .......................................................................................... 110
11.3.10. Variables ............................................................................................. 110
11.3.11. Ternary Operator (If-Then-Else) ........................................................... 111
11.3.12. List Projection and Selection ................................................................ 111
11.3.13. Collection Processors and Aggregators .................................................. 112
11.3.14. Spring Object References ..................................................................... 115
11.3.15. Lambda Expressions ............................................................................ 116
11.3.16. Delegate Expressions ........................................................................... 117
11.3.17. Null Context ....................................................................................... 117
11.4. Classes used in the examples ...................................................................................... 117
12. Validation Framework .............................................................................................................. 119
12.1. Introduction ............................................................................................................... 119
12.2. Example Usage .......................................................................................................... 119
12.3. Validator Groups ....................................................................................................... 121
12.4. Validators .................................................................................................................. 121
12.4.1. Condition Validator ............................................................................... 121
12.4.2. Required Validator ................................................................................ 122
12.4.3. Regular Expression Validator ................................................................. 122
12.4.4. Generic Validator .................................................................................. 123
Spring Framework (Version 1.3.2)
iv
788060839.004.png 788060839.005.png 788060839.006.png
 
The Spring.NET Framework
12.4.5. Conditional Validator Execution ............................................................. 123
12.5. Validator Actions ....................................................................................................... 124
12.5.1. Error Message Action ............................................................................ 124
12.5.2. Exception Action ................................................................................... 124
12.5.3. Generic Actions .................................................................................... 125
12.6. Validator References .................................................................................................. 125
12.7. Progammatic usage .................................................................................................... 126
12.8. Usage tips within ASP.NET ....................................................................................... 126
12.8.1. Rendering Validation Errors ................................................................... 127
13. Aspect Oriented Programming with Spring.NET ........................................................................ 130
13.1. Introduction ............................................................................................................... 130
13.1.1. AOP concepts ....................................................................................... 130
13.1.2. Spring.NET AOP capabilities ................................................................. 131
13.1.3. AOP Proxies in Spring.NET .................................................................. 132
13.2. Pointcut API in Spring.NET ....................................................................................... 132
13.2.1. Concepts ............................................................................................... 133
13.2.2. Operations on pointcuts ......................................................................... 133
13.2.3. Convenience pointcut implementations ................................................... 134
13.2.4. Custom pointcuts ................................................................................... 136
13.3. Advice API in Spring.NET ......................................................................................... 137
13.3.1. Advice Lifecycle ................................................................................... 137
13.3.2. Advice types ......................................................................................... 137
13.4. Advisor API in Spring.NET ....................................................................................... 142
13.5. Using the ProxyFactoryObject to create AOP proxies ................................................... 142
13.5.1. Basics ................................................................................................... 143
13.5.2. ProxyFactoryObject Properties ............................................................... 143
13.5.3. Proxying Interfaces ................................................................................ 144
13.5.4. Proxying Classes ................................................................................... 146
13.5.5. Concise proxy definitions ...................................................................... 146
13.6. Proxying mechanisms ................................................................................................. 147
13.6.1. InheritanceBasedAopConfigurer ............................................................. 148
13.8. Manipulating Advised Objects .................................................................................... 149
13.9. Using the "autoproxy" facility .................................................................................... 150
13.9.1. Autoproxy object definitions .................................................................. 150
13.9.2. Using attribute-driven auto-proxying ...................................................... 155
13.10. Using AOP Namespace ............................................................................................ 155
13.11. Using TargetSources ................................................................................................ 156
13.11.1. Hot swappable target sources ............................................................... 157
13.11.2. Pooling target sources .......................................................................... 157
13.11.3. Prototype target sources ....................................................................... 158
13.11.4. ThreadLocal target sources ................................................................... 159
13.12. Defining new Advice types ....................................................................................... 159
13.13. Further reading and resources ................................................................................... 159
14. Aspect Library .......................................................................................................................... 160
14.1. Introduction ............................................................................................................... 160
14.2. Caching ..................................................................................................................... 160
14.3. Exception Handling .................................................................................................... 162
Spring Framework (Version 1.3.2)
v
788060839.007.png 788060839.008.png 788060839.009.png
 
Zgłoś jeśli naruszono regulamin