Generic repository - IRepository or IRepository

前端 未结 1 1151
无人共我
无人共我 2020-12-12 21:06

I have seen two different approaches for creating generic repositories. What are differences between those two approaches (pros and cons) ? Please diregard difference in the

相关标签:
1条回答
  • 2020-12-12 21:29

    The biggest difference is that IRepository<T> is bound to a single type while an IRepository is potentially bound to multiple types. Which one is appropriate is highly dependent upon your particular scenario.

    Generally speaking I find IRepository<T> to be more useful. At the time of use it's extremely clear what the contents of IRepository<T> are (T). On the other hand it's not clear from a given IRepository what is contained inside of it.

    In cases where I have to store multiple types of objects, I usually create a map of IRepository<T> instances. For instance: Dictionary<T,IRepository<T>>.

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