摘要:
本文主要介绍在web应用程序中使用Castle ActiveRecord与在桌面应用程序或.Remoting程序中使用AR的一些区别,主要针对配置的不同。
如果用户在Web Application使用AR,则在配置文件(Web.config或configfile.xml)中必须添加 isWeb="true" 属性,这样迫使ActiveRecord使用另一种策略来容纳实例对象,这么做非常必要,因为在web程序中不同的线程可以为同一web请求进行服务,节 省了内存的开销。
具体的配置文件如下:
<configuration>
<activerecord
isWeb="true|false"
isDebug="true|false"
threadinfotype="custom thread info implementation"
sessionfactoryholdertype="custom session holder implementation"
namingstrategytype="custom namingstrategy implementation">
<config>
<add key="hibernate.connection.driver_class" value="NHibernate Driver" />
<add key="hibernate.dialect" value="NHibernate Dialect" />
<add key="hibernate.connection.provider" value="NHibernate Connection Provider" />
<add key="hibernate.connection.connection_string" value="connection string" />
</config>
<config type="Full Type name to Abstract Class that defines boundaries for different database">
<add key="hibernate.connection.driver_class" value="NHibernate Driver" />
<add key="hibernate.dialect" value="NHibernate Dialect" />
<add key="hibernate.connection.provider" value="NHibernate Connection Provider" />
<add key="hibernate.connection.connection_string" value="connection string" />
</config>
</activerecord>
</configuration>
<activerecord
isWeb="true|false"
isDebug="true|false"
threadinfotype="custom thread info implementation"
sessionfactoryholdertype="custom session holder implementation"
namingstrategytype="custom namingstrategy implementation">
<config>
<add key="hibernate.connection.driver_class" value="NHibernate Driver" />
<add key="hibernate.dialect" value="NHibernate Dialect" />
<add key="hibernate.connection.provider" value="NHibernate Connection Provider" />
<add key="hibernate.connection.connection_string" value="connection string" />
</config>
<config type="Full Type name to Abstract Class that defines boundaries for different database">
<add key="hibernate.connection.driver_class" value="NHibernate Driver" />
<add key="hibernate.dialect" value="NHibernate Dialect" />
<add key="hibernate.connection.provider" value="NHibernate Connection Provider" />
<add key="hibernate.connection.connection_string" value="connection string" />
</config>
</activerecord>
</configuration>
属性 | 必需 | 描述 |
---|---|---|
isWeb | 否 |
如果AR运行在ASP.NET应用程序中,该属性为true |
isDebug | 否 |
如果为true,强制AR写映射文件,用来帮助调试,该文件写到bin目录下 |
threadinfotype | 否 |
Full qualified type name to a custom implementation of IThreadScopeInfo 用户自定义的实现IThreadScopeInfo完全限定类型名称 |
sessionfactoryholdertype | 否 |
用户自定义的实现ISessionFactoryHolder完全限定类型名称 |
namingstrategytype | 否 |
用户自定义的实现INamingStrategy完全限定类型名称,这是一个NHibernate 接口 |
虽然isWeb字段并不是必需,但是对程序的性能却有一定的影响。所以个人认为在asp.net web application中使用很有必要。
文章就写到这里了,第一次写文,还请多多点评。不吝赐教!
henry