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

后端 未结 2 534
予麋鹿
予麋鹿 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:31

    There is no need for Domain Model since it will be redundancy. EF classes directly can act as Domain Model and they are converted to View Models while sending it to View. EF can be separated into different class library. Most of them use repository pattern along with any ORM incase it would be easy if they go for replacement. But I've seen criticism over using repository pattern, check this out.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题