Fluent NHibernate 哪个架构比较好?
我正在使用 MVC 3 和 Fluent NHibernate 开发一个应用程序。我想知道什么是应用程序的最佳架构,比如我们是否应该将业务层、DAL和存储层分开,稍后在业务中定义实体类和映射类,所有接口都在存储库中,所有数据逻辑都在DAL中。 有什么想法处理申请的最佳方式是什么?
谢谢
I m developing an application with MVC 3 and Fluent NHibernate. i want to know what will be the best architecture for application , like should we separate the Business layer , DAL and respository layer, define entity class and mapping class in business later , all the interfaces are in repository and all the data logic in DAL.
any ideas what is the best way to handle the application ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以将业务实体定义到单独的层中。然后,您可以使用定义这些业务实体(存储库)的 CRUD 操作的接口。然后您将拥有这些存储库的特定实现:在您的情况下使用 NHibernate。这是您拥有数据访问逻辑和 FluentNHibernate 映射的地方。最后,您将拥有一个服务层,它将定义由业务实体上的多个简单 CRUD 操作组成的复杂业务操作。业务层还可以包含业务验证逻辑。
由于存储库实现的接口,服务层和数据访问层将是弱耦合的,业务层不应该知道这些存储库的具体实现。
最后,您的 MVC 控制器将与服务方法和业务实体配合使用。您还可以在 UI 层(MVC 应用程序)中定义视图模型,以便控制器操作可以在业务实体和视图模型之间进行映射,并将这些视图模型传递给视图。
You could define your business entities into a separate layer. Then you could have interfaces defining the CRUD operations with those business entities (repositories). Then you would have a specific implementation of those repositories: in your case using NHibernate. This is where you would have your data access logic and FluentNHibernate mappings. Finally you would have a service layer which will define complex business operations consisting of multiple simple CRUD operations on your business entities. The business layer could also contain business validation logic.
The service layer and the data access layer will be weakly coupled thanks to the interfaces that your repositories implement, the business layer shouldn't know about the specific implementations of those repositories.
Finally your MVC controllers will work with the service methods and business entities. It is in the UI layer (MVC application) where you would also define view models, so that controller actions could map between the business entities and the view models and pass those view models to the views.
一个非常值得一看的开源项目是 CodeCampServer
这是我的地方已启动,并且它正在使用您感兴趣的堆栈(MVC、Fluent NHib)
A very good open source project to take a look at is CodeCampServer
This is where I started, and it is using the stack that you are interested in (MVC, Fluent NHib)
在我看来,S#arp Architecture 是一个很好的代码库,可以帮助您了解设计良好、松散耦合和领域驱动的知识使用 NHibernate 和 Fluent NHibernate 作为 ORM 的 ASP.NET MVC 项目的设计架构。
In my opionion S#arp Architecture is a great code-base to learn about well designed, loosely coupled and domain driven design architecture for a ASP.NET MVC projects using NHibernate with Fluent NHibernate as ORM.