BestPractices:这是可以接受的MVC-控制器使用多个库? [英] BestPractices: Is it acceptable to use more than one repository in a MVC-Controller?

查看:116
本文介绍了BestPractices:这是可以接受的MVC-控制器使用多个库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个员工和团队之间的许多一对多协会[。
的foreach实体我有一个资料库。

I have a many-to-many assocition between an Employee and a Team. Foreach entity I have a repository.

现在我使用ASP.NET MVC和我创建了一个EmployeeController。我还创建了一个视图编辑员工。对于这个观点我需要在团队中的一个DropDownList。问题是,我只EmployeeController得到了EmployeeRepository。所以,我怎么能得到所有团队?
我现在的解决方案是使用两个仓库。

Now I use ASP.NET MVC and I created a EmployeeController. I also created a View to edit an Employee. For this view I need a DropDownList with all Teams. The problem is that my EmployeeController only has got EmployeeRepository. So how can I get all Teams? My solution now is to use two repositories.

但是,这是一个好的解决方案?

But is this a good solution?

我能代替创建TeamController和写一个方法返回所有团队(我会怎么做)?

Could I instead create TeamController and write a method returning all Teams (how would I do that)?

推荐答案

是的,这是完全可以接受的控制器有两个仓库的引用。

Yes, it's perfectly acceptable for a controller to have references to two repositories.

事实上,我的控制器使用多个存储库工作往往不是。

In fact, my controllers work with multiple repositories more often than not.

这篇关于BestPractices:这是可以接受的MVC-控制器使用多个库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆