When sending messages with nservicebus should the messages just contain simple types and strings, or is it okay to include your own objects? If so, should these objects be lightweight data transfer objects without any behaviour?
For example sending the following message:
public class UserAuthenticatedMessage : IMessage {
public MyUserClass User { get; private set; }
public UserAuthenticatedMessage(MyUserClass user) {
User = user;
}
public object Value {
get { return User; }
}
}
Where MyUserClass contains not just properties but also behaviour:
public class MyUserClass {
public int Id { get; set; }
public string Username { get; set; }
public bool ICheckSomething(string foo) {
}
}
Is this okay / a bad idea? Should we be using a MyUserDTO class with no behaviour? Should we be sending all the fields explicitly in the message then turning into an object at the other end?
You can send nested data containers within your messages, i.e data transfer objects, but they shouldn’t have behavior.