具有多个存储库的良好MVC设计(Good MVC design with multiple repositories [closed])

编程入门 行业动态 更新时间:2024-10-24 08:19:18
具有多个存储库的良好MVC设计(Good MVC design with multiple repositories [closed])

我开始怀疑我的初始设计决策,因为我看到的所有地方都在MVC上找到教程,他们只是将访问层转储到MVC项目中。 (这违背了我所学到的一切)

BarRepo :处理对API的访问。 FooRepo :处理对我的数据库的访问(使用EF)。 FooBarHandler :将来自两个repos的数据连接到控制器的有用数据中。 控制器 :一个控制器,没什么特别的。

正如您在图片中看到的那样,我将每个部分拆分为自己的项目并尝试获得松耦合。 所以我不会从数据库层发送实体框架类等等。 但是我遇到了一些泡菜。 获取的数据量已经变得很大,以至于它在前端是显而易见的,所以我需要引入分页。 所以我按照本教程 。 我的“问题”是,现在MVC,Logic和数据库项目依赖于PagedList,所以事情不再那么整洁和闪亮。

所以我的问题是你会做什么?

I have started to doubt my initial design decision, as everywhere I look I find tutorials on MVC where they just dump the access layer right into the MVC project. (Which goes against everything I've learned)

BarRepo: Handles access to an API. FooRepo: Handles access to my Database (using EF). FooBarHandler: Joins data from the two repos into useful data for the controller. Controller: A controller, nothing speical.

As you can see in the picture, I've split up each part into their own project and try to obtain loose coupling. So I don't send Entity Framework classes out of the database layer and so on. However I've run into a bit of a pickle. The data amount fetched have become so large that it's noticeable on the frontend, so I needed to introduce paging. So I followed this tutorial. My "problem" is that now MVC, Logic and the Database projects are depended on PagedList, so things aren't so neat and shiny anymore.

So my question is what would you have done?

最满意答案

您不需要使用PagedList,因为您可以自己创建分页项目列表。 请查看此StackOverflow问题 ,了解如何执行此操作的示例。

总结一下:

var pageNum = 3; var pageSize = 20; var pagedItems = data.Skip((pageNum - 1) * pageSize).Take(pageSize).ToList();

这样你就不会在PagedList上有任何依赖,这将有助于减少你的设计中的耦合。

You don't need to use PagedList as you can create a paged list of items yourself. Take a look at this StackOverflow question for an example of how to do this.

To summarise:

var pageNum = 3; var pageSize = 20; var pagedItems = data.Skip((pageNum - 1) * pageSize).Take(pageSize).ToList();

That way you will have no dependancies on PagedList, which will help reduce the coupling in your design.

更多推荐

本文发布于:2023-08-07 11:14:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1464221.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   Good   MVC   design   repositories

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!