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
process.
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).
ex.
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?
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.
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.
Tube
Member
2 Points
10 Posts
Correct way of passing parameters to Service Layer method
Jan 24, 2012 12:30 PM|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 process.
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).
ex.
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?
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.
Ramesh T
Contributor
5079 Points
821 Posts
Re: Correct way of passing parameters to Service Layer method
Jan 24, 2012 01:32 PM|LINK
Hello Mate,
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.
Cheers.