开发者

C#: Repository pattern, is there a standard interface or should i cook my own?

开发者 https://www.devze.com 2023-02-23 07:30 出处:网络
I have been doing a bit of research with 开发者_Go百科the repository pattern and I have been rolling my own Interfaces for the repository.

I have been doing a bit of research with 开发者_Go百科the repository pattern and I have been rolling my own Interfaces for the repository.

I was wondering if there is a standard interface that I can implement that has Find methods and things like that?

And I presume I need to implement my own interface as well for thing like GetProduct, GetProducts etc?

I was also putting everything in one repository but this seems to be getting quite large, I presume I should separate them to difference repositories? I presume separate them by what they do i.e. Security, Products, Sales etc?

I do seem to remember seeing a standard type Repository interface which I think each class implements but I can't seem to find any reference to it.


If you are by chance talking about domain-driven design repositories (which I think you must not be given the way you talk about them), the code for Steve Bohlen's DDD presentation gives a standard repository interface. I wouldn't say it's used widely (i.e. is standard), but it does adhere to the DDD guidelines pretty closely (i.e. follows standards).

If you are talking about the more general concept of a data-access layer, I would be sure not to call that a repository because of the confusion with the DDD concept, and perhaps conform to the same method names etc. of stuff like the Entity Framework's ObjectContext class, or even just ICollection<T> or IDictionary<TKey, T> if appropriate.


By following related question links, I found this interesting blog post: Repository or DAO?: Repository.

It says that the appropriate interface to couple to for a Patterns of Enterprise Application Architecture repository is

public interface IRepository<T> : ICollection<T>, IQueryable<T> { }
0

精彩评论

暂无评论...
验证码 换一张
取 消