我面临以下问题:
我需要从我的控制器调用我的域层;它调用一个 Web 服务方法,该方法通过引用 (ref) 接收请求。
控制器代码:
//BusinessEntityObject is a Reference-Type (BusinessEntity) object
var request = View.BusinessEntityObject;
_workflowService.PerformAction(request);
if(request.Errors.Count != 0)
{
View.Errors = request.Errors;
return false;
}
领域层(WorkflowService.cs 类):
public void PerformAction(BusinessEntity request)
{
//TryAction(System.Action action) basically wraps action in try catch and handles exceptions
TryAction(() =>
{
_wcfClient.RequestSomething(ref request);
});
}
IF_wcfClient.RequestSomething
在返回请求对象时修改 Errors 集合具有此错误更新的错误集合。但是,一旦将控制权返回给控制器并检查了错误集合,那么我的更新就消失了。
Edit00:哦,无耻的插头,我是代表 14,我试图提出一些对我有用的问题/答案,它说我不能因为我的水平低。
Edit01:非常感谢迪伦,看到有这样一个网站来指出人们可能会错过的非常小的事情总是很好的。将值返回给我的更新代码如下所示:
领域层(WorkflowService.cs 类):
public BusinessEntity PerformAction(BusinessEntity request)
{
//TryAction(System.Action action) basically wraps action in try catch and handles exceptions
TryAction(() =>
{
_wcfClient.RequestSomething(ref request);
return request;
});
}