// Example of Controller query input model
public ActionResult Search(SearchProductsQuery query)
{
ProductSearchViewModel searchView = query.ExecuteWith(productsRepository);
return View(searchView);
}
// Exmaple of Controller command input model
public ActionResult Create(CreateProductCommand command)
{
if (command.Validate(this.ModelState))
{
var newProduct = command.CreateProduct();
productRepository.Add(newProduct);
}
return View();
}
3 回答
我有一个
User
域实体,它有一个ChangePassword
方法,接受ChangePasswordInput
类并返回ChangePasswordResult
类 .ChangePasswordInput
也用作ChangePassword
视图(窗体)的控制器输入和视图模型,ChangePasswordResult
用作ChangePasswordSuccess
视图的视图模型 .我更喜欢它在here中给出的方式 . 它区分了查询的控制器输入模型和调用服务层(存储库等)的控制器输入模型 . 我开始采用以下方法:
对控制器输出型号使用
*ViewModel
.对于Controller输入模型,请使用
*Query
,其中只是对查询中使用的参数进行封装 .对于调用服务层的控制器输入模型,请使用
*Command
.几个例子:
我通常使用
*ViewModel
作为控制器输出模型,使用*Form
作为控制器输入模型 .对于持久性(域模型/实体),我不使用任何特殊的命名约定 .