问题
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
}
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
}
We use this type of design in MVC. Is it a bad practice to do the same in Breeze?
回答1:
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.
More info on partial class use cases: When is it appropriate to use C# partial classes?
来源:https://stackoverflow.com/questions/28164906/is-it-a-good-practice-to-use-multuple