Spring.NET学习笔记(4)-对象作用域和类型转换
一.作用域
作為對象定有生命周期,singleton和prototype是最基本的實(shí)例狀態(tài),其他三個(gè)則是對于web平臺而言的。熟悉asp.net的則一看便清楚了.
| singleton | 在每個(gè)Spring IoC容器中一個(gè)bean定義對應(yīng)一個(gè)對象實(shí)例。 |
| prototype | 一個(gè)bean定義對應(yīng)多個(gè)對象實(shí)例。 |
| request | 在一次HTTP請求中,一個(gè)bean定義對應(yīng)一個(gè)實(shí)例;即每次HTTP請求將會有各自的bean實(shí)例, 它們依據(jù)某個(gè)bean定義創(chuàng)建而成。該作用域僅在基于web的Spring ApplicationContext情形下有效。 |
| session | 在一個(gè)HTTP Session中,一個(gè)bean定義對應(yīng)一個(gè)實(shí)例。該作用域僅在基于web的Spring ApplicationContext情形下有效。 |
| application | 在一個(gè)全局的HTTP Session中,一個(gè)bean定義對應(yīng)一個(gè)實(shí)例。典型情況下,僅在使用portlet context的時(shí)候有效。該作用域僅在基于web的Spring ApplicationContext情形下有效。 |
以下兩幅圖很好的表達(dá)了singleton和prototype的概念
二.類型轉(zhuǎn)換器
類型轉(zhuǎn)換器是.net已經(jīng)有的概念,其實(shí)類型轉(zhuǎn)換器的概念在.net中用的很廣,asp.net,wpf則到處是類型轉(zhuǎn)換器,只不過平時(shí)大家很少用,因?yàn)榛镜念愋?net都幫你做了內(nèi)置轉(zhuǎn)換。以下是內(nèi)置spring支持的類型轉(zhuǎn)換器,當(dāng)然也可以自己擴(kuò)展,擴(kuò)展的配置文件需要通過配置來擴(kuò)展。
| 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. |
這部分先了解,用到再看
總結(jié)
以上是生活随笔為你收集整理的Spring.NET学习笔记(4)-对象作用域和类型转换的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SQL Server 2008带字段注释
- 下一篇: 揭秘ASP.NET 2.0的Eval方法