If Entity Framework / DbContext is the DAL / Repository, where does it fit within 3-tier architecture?

后端 未结 2 491
予麋鹿
予麋鹿 2021-02-10 00:52

I\'ve been reading articles on StackOverflow and other sites all day about best architecture practices and there are just so many conflicting ideas and opinions.

I\'ve

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-10 01:35

    Here is what I do:

    Data:

    • Has one class inheriting from DbContext.
      • It has all the db sets.
      • Overrides OnModelCreating.
      • Mapping primary keys and relationships.

    Entities:

    • Has every POCO classes.
      • Each property is decorated with needed data annotations.

    Services:

    • Each service has common methods (GetList(), Find(), Create(), etc.).

    Business:

    • Called from clients, orchestrate using services to perform a specific task UserChangePassword (this will check if this can be performed, then perform the task, or return error/unauthorized statuses among many others to make the client shows the correct information regarding the task. This on my case is where I log.

    Clients (Desktop/Web/Wpf/etc).

    I'm not saying this is the best approach, I'm just sharing what's been working for me.

提交回复
热议问题