基于下面的解释和示例,在分布式应用程序的不同层之间使用类型、对象和属性的指南和建议是什么?另外,请注意,我使用了多个词来描述架构概念,我不想对SOA或DDD这样说,因为我的实现并没有完全遵循任何风格。
层和对象的使用-- UI (模型/资源)、-> Webservice (请求响应)、->业务层(域实体/业务对象)。
解释对象及其与层的关系
UI (使用模型/资源)
Webservice (响应可以包含一个或多个模型/资源以及所需的任何其他属性)
业务层(返回包含1个或多个POCO业务/域实体的响应“与web响应不一样”,这将被映射回web资源和响应)
如果我的业务层接受业务对象,或者我可以使用下面这样的属性。
我的"web“层--带有请求和响应模式的RPC样式--将请求的属性传递给我的应用程序服务层(业务层)。我的业务层将返回一个响应对象(类型属于业务层),其中包含多个POCO域实体/业务对象,这将被映射回资源和响应。
我的web /服务层
public Resources.InboundReceivingResponse Post(Resources.InboundReceivingRequest request)
{
Resources.InboundReceivingResponse response = new Resources.InboundReceivingResponse();
Granite.DomainModel.Services.ServiceResponse serviceResponse = null;
try
{
_service = new DomainModel.Services.ReceivingService();
//calling business layer with request properties and returning response (business objects)
serviceResponse = _service.Receive(request.DocumentNumber, request.Barcode, request.TrackingEntityBarcode, request.LocationBarcode,
request.MasterItemCode, request.ItemAliasCode, request.UOM, request.PackSize, request.Qty, request.UserID,
request.PalletBarcode, request.Batch, request.SerialNumber, request.ExpiryDate, request.NumberOfLabels,
request.NumberOfEntities, request.Comment, request.Reference);
//Domain object to resource
response.Document = new Resources.DocumentResponse();
response.Document.DocumentHeader = serviceResponse.Document.MapToResource(); //Domain object to resource
response.Document.DocumentLines = serviceResponse.Document.Detail.MapToResource(); //Domain object to resource
return response;
}
catch (Exception ex)
{
Logger.LogException(ex, () => request, () => response, () => serviceResponse);
throw new ApplicationException(ex.Message, ex);
}
}
我的业务层方法
public Services.ServiceResponse Receive(string documentNumber, string Barcode, string TrackingEntityBarcode,
string LocationBarcode, string MasterItemCode, string ItemAliasCode, string UOM, decimal PackSize,
decimal Qty, long UserID, string PalletBarcode, string Batch, string SerialNumber, DateTime? ExpiryDate,
int NumberOfLabels, long NumberOfEntities, string Comment, string Reference)
{
Services.ServiceResponse response = new ServiceResponse();
//...logic
response.Document = this.GetDocument(documentNumber); //this will map back to resource
response.TrackingEntities = trackingEntities;//this will map back to resource
return response;
}
发布于 2015-08-19 19:36:18
UI通过请求和响应与Web /应用层进行通信。也称为模型/资源。
Web API/应用层与DTO的业务/服务层通信,DTO要么是扁平对象,要么是业务实体。
业务层在存储库和逻辑之间使用业务实体。
帮我写Should the repository layer return data-transfer-objects (DTO)?的帖子
https://stackoverflow.com/questions/32062881
复制相似问题