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