Spring.NET学习笔记(4)-对象作用域和类型转换
一.作用域
作為對象定有生命周期,singleton和prototype是最基本的實例狀態,其他三個則是對于web平臺而言的。熟悉asp.net的則一看便清楚了.
| singleton | 在每個Spring IoC容器中一個bean定義對應一個對象實例。 |
| prototype | 一個bean定義對應多個對象實例。 |
| request | 在一次HTTP請求中,一個bean定義對應一個實例;即每次HTTP請求將會有各自的bean實例, 它們依據某個bean定義創建而成。該作用域僅在基于web的Spring ApplicationContext情形下有效。 |
| session | 在一個HTTP Session中,一個bean定義對應一個實例。該作用域僅在基于web的Spring ApplicationContext情形下有效。 |
| application | 在一個全局的HTTP Session中,一個bean定義對應一個實例。典型情況下,僅在使用portlet context的時候有效。該作用域僅在基于web的Spring ApplicationContext情形下有效。 |
以下兩幅圖很好的表達了singleton和prototype的概念
二.類型轉換器
類型轉換器是.net已經有的概念,其實類型轉換器的概念在.net中用的很廣,asp.net,wpf則到處是類型轉換器,只不過平時大家很少用,因為基本的類型.net都幫你做了內置轉換。以下是內置spring支持的類型轉換器,當然也可以自己擴展,擴展的配置文件需要通過配置來擴展。
| RuntimeTypeConverter | Parses strings representing System.Types to actual System.Types and the other way around. |
| FileInfoConverter | Capable of resolving strings to a System.IO.FileInfo object. |
| StringArrayConverter | Capable of resolving a comma-delimited list of strings to a string-array and vice versa. |
| UriConverter | Capable of resolving a string representation of a Uri to an actual Uri-object. |
| CredentialConverter | Capable of resolving a string representation of a credential for Web client authentication into an instance of System.Net.ICredentials |
| StreamConverter | Capable of resolving Spring IResource Uri (string) to its corresponding InputStream-object. |
| ResourceConverter | Capable of resolving Spring IResource Uri (string) to an IResource object. |
| ResourceManagerConverter | Capable of resolving a two part string (resource name, assembly name) to a System.Resources.ResourceManager object. |
| RgbColorConverter | Capable of resolving a comma separated list of Red, Green, Blue integer values to a System.Drawing.Color structure. |
| ExpressionConverter | Capable of resolving a string into an instance of an object that implements the IExpression interface. |
| NameValueConverter | Capable of resolving an XML formatted string to a Specialized.NameValueCollection |
| RegexConverter | Capable of resolving a string into an instance of Regex |
| RegistryKeyConverter | Capable of resolving a string into a Microsoft.Win32.RegistryKey object. |
這部分先了解,用到再看
總結
以上是生活随笔為你收集整理的Spring.NET学习笔记(4)-对象作用域和类型转换的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL Server 2008带字段注释
- 下一篇: 哥的博客不是山寨,是公益