我正在尝试实现基本控制器,应用服务,存储库设计。我是这个级别的OO设计的新手,但已经非常完整。剩下的障碍是如何处理扩展我的基本控制器。
我的目标:
这就是我所拥有的:
基础控制器:
public class BaseControllerSingle<TRepository, TViewModelSingle> : BaseController
...
// GET: /InventoryMgmt/ManageItems/Edit/5
public virtual ActionResult Edit(
int id = 0,
string pageTitleNoun = "",
Expression<Func<TRepository, bool>> predicate = null
)
{
TViewModelSingle viewModelSingle = new TViewModelSingle();
ViewBag.Mode = "EDIT";
if (id == 0) //Add new company mode
{
viewModelSingle = _baseAppServSingle.CreateNewViewModel(CurrentUserId);
ViewBag.Header = "Create New " + pageTitleNoun;
ViewBag.Mode = "NEW";
return View(viewModelSingle);
}
//else edit existing record mode
viewModelSingle = _baseAppServSingle.CreateEditViewModel(id, predicate);
ViewBag.Header = "Edit " + pageTitleNoun;
return View(viewModelSingle);
}
我的具体控制器。注意这里的代码是不正确的(特别是&#34; ItemViewModel viewModel = actionResult(ItemViewModel);&#34; ...但是试图显示我正在尝试的内容,这主要是从动作结果中提取视图模型,操作它进一步,然后返回。
public class ManageItemsController : BaseController
...
// GET: /InventoryMgmt/ManageItems/Edit/5
public ActionResult Edit(int id = 0)
{
ActionResult actionResult = GetBaseControllerSingle().Edit(
"Material",
id,
x => x.Id == id && x.CompanyId == CurrentCompanyId);
ItemViewModel viewModel = actionResult(ItemViewModel);
if (id == 0)
{
viewModel = _manageItemsAppServ.CreateNewViewModel(viewModel, CurrentCompanyId);
}
viewModel.DDLOptions = _manageItemsAppServ.CreateFilterOptionsViewModel(CurrentCompanyId);
return View(viewModel);
}
答案 0 :(得分:0)
我决定重新编写一些代码以消除这种必要性。我想也许可以用Ninject完成......但这不是我现在想要进入的东西