Repository Pattern Standardization of methods

前端 未结 7 1570
天涯浪人
天涯浪人 2021-01-30 02:05

All I am trying to find out the correct definition of the repository pattern.

My original understanding was this (extremely dumbed down)

  • Separate your Busi
相关标签:
7条回答
  • 2021-01-30 02:34

    I am a great fan of the generic repository pattern but I think you should strongly consider not directly inheriting from the interface as it can become a very large limitation especially since many times the code for the generic interface will be the same that it could be defined in an abstract base class that you will no longer be able to have more than 1 generic repository inside a class.

    I recommend having your IProductRepository implementer access the generic IRepository<Product> through delegation and inject that in through the constructor so you can compose your class of possibly many IRepositories and group them behind a single interface in a way that makes sense.

    I wrote a blog on this topic while it specifically references NHibernate this pattern can be applied to any type of repository: Creating a common generic and extensible NHiberate Repository version 2

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