1. Using the DTO is probably the best bet rather than the actual domain object as depending on how intertwined the relationships are for your object, it might be difficult to pass just the objects needed for the transaction on the remote side.
2. Stateful objects use up resources. In the COM world it's a bigger deal because when you pass an object you are basically setting up a remote proxy to which all calls are then being marshalled. If that object contains other objects, then they are being marshalled as well. In .NET though you can pass objects by value (i.e. serialization), in which case there is less to worry about. In the ASP world state was a big problem because if you created stateful objects that you stored for example in the ASP session you would be using up server resources. The importance of having stateless objects in that model is so that you can instantiate an object for a moment in time, and the release the object immediately thereby returning resources back. Instead of storing the object in the session, you store the data for the object. You then have a method that you can use (constructor) so that when you instantiate an object you can pass it the state directly to reconstruct the object.
In ASP.NET though you have many more options relating to session state, as session can either be inprocess, or stored externally in a separate process or in a database. If you are using inproc session you still have to be wary of putting objects (especially heavy objects) in the session as they will consume resources. However if you use a session state of say StateServer or SQLServer then the only objects allowed in the session will be those that are serializable. This means that the objects are serialized out of the main web server's process and are not consuming it's resources. In these cases you still want to be cautious about how much you serialize (i.e. related objects / child collections) as if you aren't careful you'll end up serializing your entire object graph, which could consume the memory of your caching server and be a signficant performance hit for each request.
3. It depends on for what reason you were intending to use the facade, I wasn't sure as to why you need one in your case. If you have a complex set of interactions in order to complete an operation, then you should have a facade to ensure that all those interactions are shielded from the caller. As far as having a facade for Services, a service itself is (or at least should be) a facacde. The service should not be a 1 to 1 representation of the internal API. The service should be an abstraction and internally handle mapping the data passed within the service message to the domain model and vice versa. This way you can change your internal implementation over time without affecting the service interface itself.
As to your example I am not clear exactly what you are trying to do. It looks like having a facade for your GetEmployee method makes sense as there are several steps involved with getting the employee and creating the DTO that you don't want the client to have to be concerned with. As to the generics, are you trying to support multiple Employee factory implementations through the IEmployee<T> interface Are you trying to support multiple DTO implementations as well as I see EmployeeDto and EmployeeBaseDto Can you clarify your intent here Where does the AddCustomer method that you mentioned in the original post fit in to this
|