混合 NHibernate DAL/BLL
我有一个现有的 asp.net webforms 项目,该项目使用 Microsoft 的 Enterprise DAAB 作为 DAL,我需要实现一些广泛的功能,并且我想使用 NHibernate 来使事情变得更容易。
是否有允许混合 DAAB/NHibernate DAL 的设计模式/架构? 这是不是一个好主意 ?
我的想法是:如果我有一个混合 DAL,我仍然可以通过 DAAB 端传递高流量/非动态查询,并节省动态 sql 生成的开销。 但仍然有 nhibernate 来处理更复杂的查询。
另外,为 asp.net webforms 应用程序设置 NHibernate DAL/BLL 的最佳方法是什么? 我已经阅读了 NHibernate 网站和其他几个网站上的教程,似乎在开始/结束 nhib 会话方面没有达成共识。 我只是在寻找最佳实践示例。
谢谢
I have an existing asp.net webforms project that uses Microsoft's Enterprise DAAB for the DAL, I need to implement some extensive features, and I would like to use NHibernate to make things easier.
Is there any design patterns/architectures out there that allow a hybrid DAAB/NHibernate DAL ? is it a good idea ?
My thinking is: if I had a hybrid DAL I could still pass high traffic/un-dynamic queries through the DAAB side and save the overhead of the dynamic sql generation. But still have nhibernate for more complex queries.
Additionally what is the best way to setup NHibernate DAL/BLL for an asp.net webforms application ? I have read the tutorial on the NHibernate site and several others there doesn't seem to be a consensus on starting/ending the nhib session. I'm just looking for best practice example.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我听说过的一种方法是在与域模型交互时使用 nHibernate。 请记住,nHibernate 可以调用存储过程,因此如果您想避免 SQL 生成,您可以这样做,但我建议您不要这样做。
如果您对报告或显示数据有查询,但不想从中创建自定义实体,则可以使用 DAAB,但如果您要创建实体,我不建议这样做。
至于最佳实践,我发现在需要时创建会话,然后将其存储在 httpContext 中,您将在每次请求时关闭会话。
唯一的另一件事是专门创建并结束一个事务,如果您的逻辑跨越多个服务,我将在您的服务层或应用程序层中执行该事务(我将服务定义为不作为 Web 服务,而是作为屏蔽的高级代码片段)来自域层的应用程序)。
Billy McCafferty 的文章是一个很好的起点: http://www.codeproject.com /KB/architecture/NHibernateBestPractices.aspx
他的代码中有一个错误/限制,如果您使用他的方法,请查看我的博客文章:http://jberke.blogspot.com/2008/10/nhibernate-transaction-session-mgmt.html
One approach I've heard about is use nHibernate for when your interact with your domain model. Keep in mind nHibernate can call stored procedures so if you want to avoid the SQL Generation you can but I'd advise against.
If you have queries for reporting or displaying data that you don't want to create custom entities from then you could use DAAB, althought I would not recommend doign this if your going to create your entities.
As for best practice, I've found that creating the Session when you need it, and then store it in httpContext, you will close the session on every reqyuest.
The only other thing then is to specificly create and end a transaction which I would do in your service layer or application tier if your logic would span multiple services (I define a service not as a webservice but as a high level piece of code which shields your application from your domain layer).
A good starting point is from Billy McCafferty's article here: http://www.codeproject.com/KB/architecture/NHibernateBestPractices.aspx
There is a bug / limitation within his code check out my blog post if you use his method: http://jberke.blogspot.com/2008/10/nhibernate-transaction-session-mgmt.html
您有两个问题 - 您或主持人应该将其分为两个问题:
1) DAAB 和 NHibernate 一起使用的最佳方式是什么?
2) 在 Web 窗体应用程序中设置 NHibernate 的最佳方法是什么?
我可以回答第二个问题,即使用 ASP.NET 中的 HttpModule 来配置每个请求的上下文。 可以在此处找到示例模块:
http://tinyurl.com/b5am9b
You have two questions - you or a moderator should split this into two:
1) What's the best way to use DAAB and NHibernate together?
2) What's the best way to set up NHibernate in a Web Forms application?
I can answer the second one, which is to use an HttpModule in ASP.NET to configure the context on each request. An example module can be found here:
http://tinyurl.com/b5am9b