1

Based on the below explanation and example, what is the guidelines and recommendation for use of types, objects and properties between the different layers of a distributed application? Also note that I use more than one word for the architectural concept I dont want to make this about SOA or DDD seeing that my implementation is not following any style religiously.

Layers and use of objects UI (models/resources) -> Webservice (Request Response) -> business layer (domain entities/ business objects).

Objects explained and relationship to layer

UI (uses the models/resources)

Webservice (Response can contain 1 or more models/resources and any other properties needed)

Business Layer (returns a response "not same as web response" that contains 1 or more POCO business/domain entities, this will be mapped back to web resource and response)

Should my business layer take in business objects or can I use properties like example below.

My "web" layer a RPC style with request and response pattern will pass the properties of the request on to my application service layer (business layer). My business layer will return a response object (the type belongs to the business layer) which contains multiple POCO domain entities/business objects, this will be mapped back to the resources and response.

My web API/Service layer

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

My business layer method

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;
}
Francois Taljaard
  • 1,339
  • 2
  • 12
  • 33
  • I found this which is related to my question http://stackoverflow.com/questions/11975453/what-is-the-best-practice-to-define-method-signature-in-service-oriented-archite – Francois Taljaard Aug 18 '15 at 03:09
  • http://stackoverflow.com/questions/6310400/is-this-a-proper-use-of-dto/6310507#6310507 this clarified for me, – Francois Taljaard Aug 20 '15 at 03:31

1 Answers1

0

UI communicate with Web API/Application layer via Request and Response. Also called Models/Resources.

Web API/Application Layer communicate back to business/service layer with DTO's. DTO is either flatten objects or business entities.

Business layer use business entities between repositories and logic.

Posts that helped me Should the repository layer return data-transfer-objects (DTO)?

Is this a proper use of DTO?

Community
  • 1
  • 1
Francois Taljaard
  • 1,339
  • 2
  • 12
  • 33