使用 Spring.NET 和 FluentNHibernate 配置 ASP.NET MVC 2
我正在尝试配置 ASP.NET MVC 2 RC 和 Spring .NET 1.3 以使用 FluentNHibernate。
我已经设法让 FluentNHibernate 在控制台应用程序中运行。
目前 ASP.NET MVC 2 RC 和 Spring .NET 对我来说工作得很好,但我在配置 FluentHibernate 时遇到了麻烦。
在问这个问题之前我已经 Google 了很多,也浏览了 StackOverflow 上的相关问题。
我知道有这个(http ://www.bennymichielsen.be/post/2009/01/04/Using-Fluent-NHibernate-in-SpringNet.aspx)博客文章和 Spring .NET 文档 ORM 章节 (http://www.springframework.net/doc-latest/reference/html/orm.html)
就像 Benny 的博客建议我创建了“FluentNHibernateLocalSessionFactoryObject”一样,该类的内容与博客文章中的内容相同。
我的 Spring 配置文件如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:db="http://www.springframework.net/database"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object id="MySessionFactory" type="Project.Core.NHinbernate.FluentNHibernateLocalSessionFactoryObject, Spring.Data.NHibernate20">
<property name="DbProvider" ref="DbProvider"/>
<property name="FluentNHibernateMappingAssemblies">
<list>
<value>Project.Core.NHibernate</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="hibernate.dialect" value="NHibernate.Dialect.MsSql2008Dialect"/>
<entry key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
</dictionary>
</property>
</object>
<object id="HomeController" singleton="false" type="Project.UI.Controllers.HomeController">
<property name="MySessionFactory" value="MySessionFactory" />
</object>
</objects>
我认为此配置缺少很多东西(连接字符串、正确的 SQL Server 2008 方言和数据库提供程序)。
我的目标是简单地将 SessionFactory 注入 HomeController 中。
如果您能指出我的配置文件中应该更改哪些内容,我将非常感激。
非常感谢!
I'm trying to configure ASP.NET MVC 2 RC and Spring .NET 1.3 to use FluentNHibernate.
I've managed to get FluentNHibernate running inside console application.
At moment ASP.NET MVC 2 RC and Spring .NET are working fine for me, but I'm having trouble configuring FluentHibernate.
Before asking this question I have Googled a lot, I have also looked through relevant questions on StackOverflow.
I know that there is this (http://www.bennymichielsen.be/post/2009/01/04/Using-Fluent-NHibernate-in-SpringNet.aspx) blog post and Spring .NET documentation ORM chapter (http://www.springframework.net/doc-latest/reference/html/orm.html)
Just like Benny's blog suggests I have created "FluentNHibernateLocalSessionFactoryObject" the contents of this class is same as in blog post.
My Spring configuration file looks like this:
<?xml version="1.0" encoding="utf-8" ?>
<objects xmlns="http://www.springframework.net"
xmlns:db="http://www.springframework.net/database"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net http://www.springframework.net/xsd/spring-objects.xsd">
<object id="MySessionFactory" type="Project.Core.NHinbernate.FluentNHibernateLocalSessionFactoryObject, Spring.Data.NHibernate20">
<property name="DbProvider" ref="DbProvider"/>
<property name="FluentNHibernateMappingAssemblies">
<list>
<value>Project.Core.NHibernate</value>
</list>
</property>
<property name="HibernateProperties">
<dictionary>
<entry key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<entry key="hibernate.dialect" value="NHibernate.Dialect.MsSql2008Dialect"/>
<entry key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
</dictionary>
</property>
</object>
<object id="HomeController" singleton="false" type="Project.UI.Controllers.HomeController">
<property name="MySessionFactory" value="MySessionFactory" />
</object>
</objects>
I think this configuration has a lot of things missing (connection string, correct SQL Server 2008 dialect and DB provider).
My goal is to simply inject SessionFactory into HomeController.
I would be very greatful if you could point out what should be changed in my configuration file.
Thank You very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然我没有使用过 ASP.NET MVC,但您确实需要将 DbProvider 添加到您的配置文件中。 DbProvider 将保存连接字符串。因此,将其添加到您的配置文件中。
为了使用 db:provider 语法,您还需要将其添加到应用程序配置文件 (web/app.config)
这是 Spring.NET 文档的相关链接
另请参阅 Benny 博文的评论,其中有更新的代码示例。
While I haven't worked with ASP.NET MVC you indeed need to add a DbProvider to your configuration file. The DbProvider will hold the connection string. So add this to your configuration file.
In order to use the db:provider syntax you'll also need to add this to your application configuration file (web/app.config)
Here's the relevant link to Spring.NET's documentation
Also look in the comments of the blogpost of Benny, there's an updated code sample.