What is the best practice to define service call prototype/signature while developing application in service oriented architecture.
For Example I want to create Service call to send email.
Let say I have following object in my domain layer
[datacontract]
public class Email
{
public string To { get; set; }
public string From { get; set; }
public string Message { get; set; }
public string Subject { get; set; }
//I am not going to use this properties in send email method
public string OtherProp1 {get; set;}
public string OtherProp2 {get; set;}
public string OtherProp3 {get; set;}
}
Should I create Service method signature like
public bool SendEmail(string from,string to, string subject,string message){//My Logic}}
Or
public bool SendEmail(Email myEmail){//My Logic}
I am leaning toward first option.(Having said that I know if object is way to complex than it make sense to pass whole object itself.)
Unfortunately, second option is less clear in this case and this is because of your Email class
.
Suppose I am to call your method. You make me pass an instance of the Email
class. I go to the class contract and find 7 properties.
And, how am I supposed to know which parameters are mandatory and which are optional? From the docs? Not a cleanest design if I have to consult the docs to make proper use of the API.
I would rather refactor your Email class to call it EmailRequest
with all these optional parameters removed and then I would create yet another class EmailResponse
if you ever need to use it as a return value of a service.