ASP.NET MVC、Spring.NET、NHibernate 初始设置/示例/教程
您是否做过一些涉及 Spring.NET 和 NHibernate 的 ASP.NET MVC 开发?我希望看到此类设置的信息丰富的示例,这样我就可以以此为基础构建自己的项目。
我尝试谷歌搜索,发现了一些漂亮的东西,比如 S#arp Architecture,一篇关于常规 ASP.NET (WebForms) 与框架集成的文章等等。尽管如此,我仍然缺少有关 ASP.NET MVC 和 ASP.NET MVC 的优秀教程。主题。
PS:我确实知道 Spring 和 Hibernate 是如何工作的,我只需要将它们插入到 MVC 应用程序中即可。现在不想使用 S#arp 架构。
PPS:我稍后会更新链接,包括这个:
Have you been doing some ASP.NET MVC developement involving Spring.NET and NHibernate both? I would like to see an informative example of such setup, so I could build my own project off that.
I tried googling, found some pretty things like S#arp Architecture, an article about regular ASP.NET (WebForms) integrated with the frameworks and so on. Still, I'm missing a good tutorial on ASP.NET MVC & the subj.
P.S.: I do know how Spring and Hibernate works, I just need to plug them into an MVC application. Don't want to use S#arp Architecture by now.
P.P.S: I'll update the links later, including this one:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
NHibernate 配置与 Spring.Net Webforms 应用程序没有什么不同。将
OpenSessionInView
模块添加到web.config
中,并在 spring 配置中定义一个名为SessionFactory
的会话工厂。Spring.Net 和 MVC 集成是通过在应用程序启动时注册自定义
IControllerFactory
来完成的,这将应用自定义ControllerActionInvoker
。控制器工厂创建或配置控制器,操作调用程序配置任何ActionFilter
。Mvc Contrib 有一个类似的 SpringControllerFactory,尽管它没有配置操作过滤器。它是在应用程序启动时配置的:
NHibernate configuration is no different to a Spring.Net webforms app. Add the
OpenSessionInView
module toweb.config
and define a session factory namedSessionFactory
in the spring config.Spring.Net and MVC integration is done by registering a custom
IControllerFactory
in application startup, this applies a customControllerActionInvoker
. The controller factory creates or configures controllers and the action invoker configures anyActionFilter
.Mvc Contrib has a similar SpringControllerFactory, though it does not configure action filters. It is configured in application startup:
对于 nhibernate,请查看 Stephen Bohlen 的网络广播 Summer of Nhibernate 和 敏捷之秋。
就我个人而言,我没有使用过 Sprint.net,但我发现这个 screencast 对获得总体概述。 Fredrik Normen 还在 asp.net MVC 和 spring.net。
For nhibernate have a look at Stephen Bohlen's webcasts Summer of Nhibernate and Autumn of Agile.
Personally I haven't used Sprint.net but this screencast I found useful to get a general overview. Fredrik normen also has a post on asp.net MVC and spring.net.
我也很难找到 NHibernate、Spring.NET 和 ASP.NET MVC 示例。我找到了 Spring.NET/NHibernate Northwind 示例(使用 WebForms 模式),但找不到在我的模型中使用 NHibernate DAO 的简单方法。
最后,我找到了 这个,发现它非常有帮助。
I too was having a hard time finding a NHibernate, Spring.NET and ASP.NET MVC example. I found the Spring.NET/NHibernate Northwind example (uses WebForms pattern), but could not find a simple way to use NHibernate DAO's with my model.
Finally, I found this one and found it to be very helpful.
我终于成功地为我的 ASP.NET MVC 应用程序提供了 Spring.NET 设施。只需编写一个自定义控制器工厂(足够简单),然后,给定一个全局 Spring 上下文(我手动创建),我就可以拉出我的控制器并执行我之前所做的任何操作。
一些有用的链接,但不是全部:
http://www.pnpguidance.net/Post/SetDefaultControllerFactoryIControllerFactoryASPNETMVCFramework.aspx
http://weblogs.asp.net/seanmcalinden/archive/2010/01/13/custom-ioc-container-for-dependency-injection-with-an-asp-net-mvc -website-usage-example.aspx
从那时起,与 NHibernate 的集成一定非常简单:)
PS:问题是:a) MVCContrib 现在似乎否认对 IoC 容器的需要,因为我听说过一些事情关于 ASP MVCContrib 中的 IoC/DI 弃用。我想,这就是为什么我无法让他们的 SpringControllerFactory 工作(与 Spring 的 WebSupportModule 一样)
b)有一些文章考虑了所需的集成,但是从某种意义上说,它们似乎都是原始的(也许是因为其中许多只是提供了不起作用的解决方案?:))
I've finally managed to provide my ASP.NET MVC application with Spring.NET facilities. Just wrote a custom contoller factory (simplistic enough), then, given a global Spring context (which I create manually), I can just pull out my controllers and do whatever I did before.
Some useful links, but not all:
http://www.pnpguidance.net/Post/SetDefaultControllerFactoryIControllerFactoryASPNETMVCFramework.aspx
http://weblogs.asp.net/seanmcalinden/archive/2010/01/13/custom-ioc-container-for-dependency-injection-with-an-asp-net-mvc-website-usage-example.aspx
Since then, integration with NHibernate must be pretty straightforward :)
P.S.: The problem is: a) MVCContrib seems to be denying the need for IoC containers now, cause I've heard something about IoC/DI deprecation in ASP MVCContrib. I guess, that's why I couldn't manage to get their
SpringControllerFactory
work (as usual withWebSupportModule
of Spring's)b) There are some articles, considering the required integration, but they all seem to be.. raw in some sense (maybe because many of the just provide the solutions that do not work? :))