I used Nhibernate in the past. Today I finally added springnet, because Hibernate and spring were first introduced in Java, while in. in net, the two are very similar, so my configuration is somewhat similar to Java. Let's take a look at the version used: nhibernate1.2, springnet1.1, and netframework2.0. Today's configuration may be somewhat outdated, but we will upgrade it later.Code:
Web. config
<? XML version = "1.0"?>
<Configuration>
<Configsections>
<Sectiongroup name = "Spring">
<Section name = "context" type = "Spring. Context. Support. webcontexthandler, spring. Web"/>
<Section name = "objects" type = "Spring. Context. Support. defaultsectionhandler, spring. Core"/>
</Sectiongroup>
<Section name = "springoverrideproperty" type = "system. configuration. namevaluesectionhandler"/>
<Section name = "Nhibernate" type = "system. configuration. namevaluesectionhandler, system, version = 1.0.5000.0, culture = neutral, publickeytoken = b77a5c561934e089"/>
</Configsections>
<Spring>
<Context>
<Resource uri = "config: // spring/objects"/>
<Resource uri = "assembly: // springresource. APP/springresource/spring_bean_dao.xml"/>
</Context>
<Objects xmlns = "http://www.springframework.net % 22/>
</Spring>
<Appsettings/>
<System. Web>
<Sessionstate timeout = "30" mode = "StateServer"/>
<Pages validaterequest = "false"/>
<Globalization requestencoding = "gb2312" responseencoding = "gb2312" Culture = "ZH-CN" uiculture = "ZH-CHS"/>
<Compilation DEBUG = "true">
<Assemblies/>
</Compilation>
<Authentication mode = "Windows"/>
<Httpmodules>
<Add name = "Spring" type = "Spring. Context. Support. websuppmodule module, spring. Web"/>
</Httpmodules>
<Httphandlers>
<Add verb = "*" Path = "*. aspx" type = "Spring. Web. Support. pagehandlerfactory, spring. Web"/>
</Httphandlers>
</System. Web>
</Configuration> V
The springnet Web framework has been used here, so that dependencies on the ASPX page can be injected .............
Spring_bean_dao.xml
<? XML version = "1.0" encoding = "UTF-8"?>
<Objects xmlns = "http://www.springframework.net /"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://www.springframework.net/http://www.springframework.net/xsd/spring-objects.xsd">
<! -- Definitions of images encapsulated by sessionfactory of nhib.pdf -->
<Object ID = "sessionfactory" type = "Spring. Data. nhib.pdf. localsessionfactoryobject, spring. Data. nhibernate12">
<Property name = "dbprovider" ref = "dbprovider"/>
<Property name = "mappingassemblies">
<List>
<Value> springdemo. Model </value>
</List>
</Property>
<Property name = "hibernateproperties">
<Dictionary>
<Entry key = "hibernate. Connection. provider" value = "nhib.pdf. Connection. driverconnectionprovider"/>
<Entry key = "hibernate. dialect" value = "nhib.pdf. dialect. mssql2005dialect"/>
<Entry key = "hibernate. Connection. driver_class" value = "nhib.pdf. Driver. sqlclientdriver"/>
<Entry key = "show_ SQL" value = "true"/>
</Dictionary>
</Property>
</Object>
<! -- Configure the driver, which is similar to the driver package in Java -->
<Object ID = "dbprovider" type = "Spring. Data. Common. dbproviderfactoryobject, spring. Data">
<Property name = "provider" value = "SqlServer-2.0"/>
<Property name = "connectionstring" value = "Data Source = (local); database = web; user id = sa; Password = sa; trusted_connection = false"/>
</Object>
<Object ID = "hibernatetransactionmanager" type = "Spring. Data. nhib.pdf. hibernatetransactionmanager, spring. Data. nhibernate12">
<Property name = "dbprovider" ref = "dbprovider"/>
<Property name = "sessionfactory" ref = "sessionfactory"/>
</Object>
<! -- Transaction encapsulation object in nhib.pdf -->
<Object ID = "transactioninterceptor" type = "Spring. transaction. Interceptor. transactioninterceptor, spring. Data">
<Property name = "transactionmanager" ref = "hibernatetransactionmanager"/>
<Property name = "transactionattributesource">
<Object type = "Spring. transaction. Interceptor. attributestransactionattributesource, spring. Data"/>
</Property>
</Object>
<! -- Dao -->
<Object ID = "userdaoimpl" type = "springdemo. Dao. userdaoimpl, springdemo. Dao">
<Property name = "sessionfactory" ref = "sessionfactory"/>
</Object>
<! -- Biz -->
<Object ID = "userbizimpl" type = "springdemo. biz. userbizimpl, springdemo. Biz">
<Property name = "userdao" ref = "userdaoimpl"/>
</Object>
<! -- Aspx -->
<Object type = "~ /Default. aspx ">
<Property name = "userbiz" ref = "userbizimpl"/>
</Object>
</Objects> <? XML version = "1.0" encoding = "UTF-8"?>
<Objects xmlns = "http://www.springframework.net /"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://www.springframework.net/http://www.springframework.net/xsd/spring-objects.xsd">
<! -- Definitions of images encapsulated by sessionfactory of nhib.pdf -->
<Object ID = "sessionfactory" type = "Spring. Data. nhib.pdf. localsessionfactoryobject, spring. Data. nhibernate12">
<Property name = "dbprovider" ref = "dbprovider"/>
<Property name = "mappingassemblies">
<List>
<Value> springdemo. Model </value>
</List>
</Property>
<Property name = "hibernateproperties">
<Dictionary>
<Entry key = "hibernate. Connection. provider" value = "nhib.pdf. Connection. driverconnectionprovider"/>
<Entry key = "hibernate. dialect" value = "nhib.pdf. dialect. mssql2005dialect"/>
<Entry key = "hibernate. Connection. driver_class" value = "nhib.pdf. Driver. sqlclientdriver"/>
<Entry key = "show_ SQL" value = "true"/>
</Dictionary>
</Property>
</Object>
<! -- Configure the driver, which is similar to the driver package in Java -->
<Object ID = "dbprovider" type = "Spring. Data. Common. dbproviderfactoryobject, spring. Data">
<Property name = "provider" value = "SqlServer-2.0"/>
<Property name = "connectionstring" value = "Data Source = (local); database = web; user id = sa; Password = sa; trusted_connection = false"/>
</Object>
<Object ID = "hibernatetransactionmanager" type = "Spring. Data. nhib.pdf. hibernatetransactionmanager, spring. Data. nhibernate12">
<Property name = "dbprovider" ref = "dbprovider"/>
<Property name = "sessionfactory" ref = "sessionfactory"/>
</Object>
<! -- Transaction encapsulation object in nhib.pdf -->
<Object ID = "transactioninterceptor" type = "Spring. transaction. Interceptor. transactioninterceptor, spring. Data">
<Property name = "transactionmanager" ref = "hibernatetransactionmanager"/>
<Property name = "transactionattributesource">
<Object type = "Spring. transaction. Interceptor. attributestransactionattributesource, spring. Data"/>
</Property>
</Object>
<! -- Dao -->
<Object ID = "userdaoimpl" type = "springdemo. Dao. userdaoimpl, springdemo. Dao">
<Property name = "sessionfactory" ref = "sessionfactory"/>
</Object>
<! -- Biz -->
<Object ID = "userbizimpl" type = "springdemo. biz. userbizimpl, springdemo. Biz">
<Property name = "userdao" ref = "userdaoimpl"/>
</Object>
<! -- Aspx -->
<Object type = "~ /Default. aspx ">
<Property name = "userbiz" ref = "userbizimpl"/>
</Object>
</Objects>