ASP.NET MVC using the Repository Pattern

前端 未结 6 836
天涯浪人
天涯浪人 2021-02-05 20:41

Currently im using EF and using its datacontext directly in all of my actions, but since i started reading about loose coupling and testability im thinking that thats not the be

6条回答
  •  轮回少年
    2021-02-05 21:27

    ObjectContext uses connection pooling, so it won't be as inefficient as you might think. Also, SQL servers (i.e. MSSQL) are really optimized for tons of concurrent connections.

    As for how to implement it, I'd go with some IRepository interface. You can then make specific interfaces, i.e. PostRepository > IRepository, and finally, implement that in concrete classes (for example, a real class, and a fake in-memory one for testing).

提交回复
热议问题