I'm developing N-Tier application in C#. Server side consists of this layers:
- Data access layer (EF Code First Entities and DbContext)
- Business layer (contains all business logic and objects)
- WCF Service layer (per-call instanstiated services that expose some operations from business layer)
Now client requests are processed in this way:
- Client creates Request DTO and sends it to Service layer
- Service layer maps this DTO to business object and calls BL method
- Business layer does something useful, makes requests to DAL, and then returns some business object to service
- Service layer maps business object to DTO Response and returns to client
It works nice despite code duplication which is mitigated by Automapper. The actual problem is this:
Client shows same objects in different views: grid, form, etc. For example, grid(list) view requires only Id and Name from User object, while Form(details) view needs every User's property. But Business layer knows nothing about views. It can only provide full UserBL object to Service calls and then it's the Service responsibility to map this UserBL to UserListDto or UserDetailsDto. And for some heavy objects, fetching extra fields from DB become a performance issue.
So, should Business layer provide different methods for different client operations? I don't like this solution because it looks like domain logic polluting, but I don't know what else could be done.