Last post Jan 24, 2012 09:32 AM by Ramesh T
Jan 24, 2012 08:30 AM|Tube|LINK
In a N-layer architecture I have a service layer, implementing use cases which will be called from the Presentation layer. The presentation layer is an asp.net web application and the service layer is a class library. Both running on same server in same
To save time and effort I'm not using DTO to move data between UI and service layer. Instead I'm using POCO objects from my domain model when needed.
Let's say I have an OrderService for handling orders in a webshop. I understand Get* methods for returning order(s).
Order GetOrderById(int orderId);
What's confusing me is how I should pass in parameters to i.e. an AddOrder method. Which one of the following do you thing would be the better approach and why?
void AddOrder(Order order);
void AddOrder(string IpAddress, string customerName, string customerEmail,..., List<int> productIDs);
In the first case the entire graph of objects is built up in UI and the passed to the service layer to be persisted. In the second case the details of an order is passed in as primitive data types and the object graph is built in the service layer method
and the persisted to db.
Jan 24, 2012 09:32 AM|Ramesh T|LINK
I would advise you to go with your first approach, which will ease your code maintenance. Just think about number of places that should be modified (and tested) in case if an enhancement comes in (that needs additional attributes to be added to your domain/entity)
and you have implemented service layer using your second approach and you consumed it in multiple places.
Note : The second approach cost you a lot in case if you have your services hosted in a seperate server and an enhancement comes in as said above.