使用多个练习是一个好习惯吗 [英] Is it a good practice to use multuple

查看:69
本文介绍了使用多个练习是一个好习惯吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新来。在我们的应用程序中,我们有多个存储库和一个微风API控制器来处理通信。但是,由于应用程序很大,因此微风控制器分为几个部分类,从而将关注点分离了。例如,我们有相关的存储库来处理Location,Holiday和Service实体,并且为了与这些实体进行通信,我们使用一个部分类控制器。

I'm quite new to breeze. In our application, we have multiple repositories and one breeze API controller to handle the communication. However, since the application is large, the breeze controller is separated in to several partial classes, separating concerns. For example, we have related repositories to handle Location, Holiday and Service entities, and to make communications related to these entities we use one partial class controller. And several others for the other repositories.

//ClientLocationController.cs
public partial class ClientController : ApiController {
      //handles location related communication
}

//ClientUserController.cs
public partial class ClientController : ApiController {
      //handle user related communication
}

我的问题是,使用扩展BreezeController的多个控制器是一种不好的做法吗?在上面的示例中,我们可以使用两个控制器代替部分类吗?

My question is, is it a bad practice use multiple controllers that extend the BreezeController? In the above example, instead of the partial class can we use two controllers as follows?

//ClientLocationController.cs
 public class ClientLocationController : ApiController {
      //handles location related communication
}


//ClientUserController.cs
public class ClientUserController : ApiController {
      //handle user related communication
}

我们在MVC。在Breeze中执行相同的操作是不好的做法吗?

We use this type of design in MVC. Is it a bad practice to do the same in Breeze?

推荐答案

为不同的功能区域或域使用单独的控制器类是

Using separate controller classes for different functional areas or "domains" is a common way to separate concerns.

如果您有许多功能区,每个功能区都有自己的实体集,则单独的控制器类特别有用。

Separate controller classes are especially helpful if you have many functional areas, each with their own sets of entities.

某些实体类型甚至可能使用一个控制器。

Some might even use one controller per entity type.

按照您所描述的方式使用部分类将被视为更多的代码组织实践(或反实践),类似于代码区域。如果您确实想要分离事物,请避免某些事情。

Using partial classes in the manner you've described would be considered more of a code organization practice (or anti-practice) akin to code regions. Something to be avoided if you truly want to separate things.

有关部分类用例的更多信息:何时使用C#局部类?

More info on partial class use cases: When is it appropriate to use C# partial classes?

这篇关于使用多个练习是一个好习惯吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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