Repository Pattern Standardization of methods

前端 未结 7 1804
天涯浪人
天涯浪人 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:33

    With the introduction of LINQ in .NET, a generic repository pattern becomes much easier to realize:

    public interface IRepository : IQueryable
    {
        void Add(T item);
        void Remove(T item);
    }
    

    To qualify as a repository, it merely needs to be able to access data in the underlying store (easily provided by IQueryable) and modify the contained data.

    You can provide extensions to the base interface to provide hooks for more entity-specific behaviour (such as wiring into a stored procedure call for a SQL-based repository), but the majority of operations can be completed by the simple interface.

提交回复
热议问题