在面向服务的应用程序中使用参数和对象

Use of parameters and objects in service oriented applications

根据下面的解释和示例,在分布式应用程序的不同层之间使用类型、对象和属性的准则和建议是什么?另请注意,我使用了不止一个词来表示架构概念我不想将其用于 SOA 或 DDD,因为我的实现没有虔诚地遵循任何风格。

图层和对象的使用 UI (models/resources) -> Web 服务(请求响应) -> 业务层(域实体/业务对象)。

解释的对象和与图层的关系

UI(使用models/resources)

Webservice(响应可以包含 1 个或多个 models/resources 以及所需的任何其他属性)

业务层(return一个包含 1 个或多个 POCO business/domain 实体的响应 "not same as web response",这将被映射回网络资源和响应)

我的业务层应该接受业务对象还是可以使用如下示例所示的属性。

我的 "web" 层具有请求和响应模式的 RPC 样式会将请求的属性传递到我的应用程序服务层(业务层)。我的业务层会return一个包含多个POCO域entities/business对象的响应对象(类型属于业务层),这将映射回资源和响应。

我的网站API/Service层

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;
}

UI 通过请求和响应与 Web API/Application 层通信。也称为 Models/Resources.

Web API/Application 层与 DTO 通信回 business/service 层。 DTO 要么是扁平化对象,要么是业务实体。

业务层在存储库和逻辑之间使用业务实体。

对我有帮助的帖子 Should the repository layer return data-transfer-objects (DTO)?

Is this a proper use of DTO?