Repository pattern with Entity framework

后端 未结 4 2100
我寻月下人不归
我寻月下人不归 2020-12-12 20:01

Repository pattern is used to abstract from particular database and object-relation-mapping technology(like EF) used. So I can easily replace (for example) my Entity framewo

4条回答
  •  萌比男神i
    2020-12-12 20:20

    Having the ability to switch from one persistence techonology to another is nice and all, but do you really need it?

    First of all, what is a repository? By Fowler's definition it provides an in-memory collection-like access to domain objects. But every modern ORM tool already does that, so another level of abstraction just adds a bit more complexity.

    Second, switching from one persistence technology to another is usually more complex than just providing another repository implementation. For instance, how do you intend to handle transactions? Transactions usually depend on context and are handled outside repositories. You could of course use some kind of unit of work implementation, but then you would have to implement new unit of work for every persistence technology.

    I do not mean to say that you should not use repositories, just maybe give it another thought.

提交回复
热议问题