如何构建三层解决方案?

发布于 2024-12-04 13:19:48 字数 1021 浏览 1 评论 0原文

我在我的解决方案中使用 FluentNHibernate。 Fluentnhibernate 文档推荐的文件夹结构是这样的:

Entities 文件夹,在该文件夹下我们有业务模型的 POCO 类。 Mappings 文件夹,在该文件夹下有数据模型的映射。

我假设这两个文件夹将进入一个名为“BusinessModel”的业务层项目?参见下文:

BuessinessModel
    |_ Entities
          |- Student.cs
          |- Course.cs
          |- Faculty.cs
    |_ Mappings
          |- Mappings.cs

也许创建另一个名为“DataAccess”的项目,该项目引用数据访问层的 BusinessModel 项目来执行 CRUD?

最好的做法是什么?那里有建筑师吗?谢谢。


AK:我在 n-layered 上阅读了您的帖子架构 - BLL、DAL 和接口。最佳实践是什么?

让我引用你的

以“人”为例:思考不同的数据 与一个人相关的操作(获取单个人的所有数据 person,许多人的浅层数据的集合,CRUD 操作、搜索等)-然后沿着逻辑设计接口 分组。

我正在尝试理解这一点。所以,你是说

  1. 在 BLL 项目中,我们有这个 Person 类。

  2. 此外,在 BLL 项目中,我们有一个声明所有数据的接口 我们需要 Person 对象的操作方法。

  3. 然后在DAL项目中,我们有具体的实现 我们在BLL中定义的接口。

    您觉得这听起来正确吗?谢谢。

I am using FluentNHibernate in my solution. The recommended folder structure from fluentnhibernate documenation is like this:

Entities folder, under which we have POCO classes of the business model.
Mappings folder, under which we have the mappings to our data model.

I assume that these two folders would go into a business layer project called "BusinessModel"? See below:

BuessinessModel
    |_ Entities
          |- Student.cs
          |- Course.cs
          |- Faculty.cs
    |_ Mappings
          |- Mappings.cs

And maybe create another project called "DataAccess" which references the BusinessModel project for the data access layer to do the CRUD?

What's the best practice? Any architect there? Thanks.


AK: I read your post at n-layered architecture - BLL, DAL and interfaces. What is best practice? .

Let me quote yours

Taking a "Person" as an example: think about the different data
operations associated with a person (Getting all the data for a single
person, a collection of shallow data for many persons, CRUD
operations, searching, etc) - then design interfaces along logical
groupings.

I am trying to understand this. So, you are saying that

  1. In the BLL project, we have this Person class.

  2. Also in the BLL project, we have an interface which declares all data
    operation methods we will need for the Person object.

  3. Then in the DAL project, we have concrete implementation of the
    interface we define in BLL.

    Does this sound correct to you? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一花一树开 2024-12-11 13:19:48

虽然盲目地将相同的架构应用于每个解决方案/项目是危险的;我的标准/默认方法是这样的:

高级别

  • 我们的目标是 3 层,我们假设是:UI、BL(业务逻辑)、DA(数据访问)。
  • 它(可能)由以下 4 个组件逻辑块(想想命名空间)组成:Common、UI、BL、DA。请记住,这 4 个块中的每一个都可能有多个代码级项目。
  • Common 是我们粘贴其他 3 个需要共享的东西的地方 - 例如 POCO。

您的具体细节

  • 在 Common 中创建 BusinessModel(可能作为独立项目)。
  • 我猜测映射取决于物理数据源,因此应该进入具体的 DA 实现。

其他说明

  • 最佳/常见做法是松散地耦合我们的主要块(尤其是 BL 和 DA);通常使用依赖注入。
  • 这将通过定义 Inferface 来实现,这些接口将/可以使用来自 Common 的 POCO 或您的 BusinessModel 实体。

While it's dangerous to go blindly applying the same architecture to every solution / project; my standard / default approach would be something like this:

High Level

  • we're aiming for 3-Tiers, which we assume are: UI, BL (Business Logic), DA (Data Access).
  • That's going to (probably) be made up of the following 4 logical chunks (think namespaces) of components: Common, UI, BL, DA. Keep in mind that each of these 4 chunks will probably have more than one code level project.
  • Common is where we'll stick things which the other 3 need to share - POCO's for example.

Your Specifics

  • Make BusinessModel (probably as a standalone project) inside Common.
  • Mappings I'm guessing is dependent on the physical data source, so that should go into the concrete DA implementation.

Other Notes

  • Best / common practice is to loosely couple our main chunks (especially the BL and DA); usually using Dependency Injection.
  • This will be achieved by defining Inferfaces, and these interfaces will/can use the POCO's or your BusinessModel entities - from the Common.
盛夏已如深秋| 2024-12-11 13:19:48

您需要将具体数据访问与业务层分开,最好创建一个具有实体(域模型)和存储库接口的业务层。

然后创建数据访问的具体实现,其中包括使用 FluentnHibernate 进行数据访问的映射和具体存储库。

商业性
|_ 实体
|- Student.cs
|- 课程.cs
|- 学院.cs
|_ 存储库接口
|- IStudentRepository.cs
|- ICourseRepository.cs

DAL(具体 - 使用 FluentNHibernate)
|_ 映射
|- 映射.cs
|_ 存储库
|- StudentRepository.cs
|- CourseRepository.cs

You need to separate the concrete data access from the business layer, preferable to create a business layer with entities (domain model) and repository interfaces.

Then create a concrete implementation of Data access which includes mappings and concrete repositories for data access using fluentnhibernate.

Buessiness
|_ Entities
|- Student.cs
|- Course.cs
|- Faculty.cs
|_ RepositoryInterfaces
|- IStudentRepository.cs
|- ICourseRepository.cs

DAL (Concrete - using FluentNHibernate)
|_ Mappings
|- Mappings.cs
|_ Repositories
|- StudentRepository.cs
|- CourseRepository.cs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文