nServiceBus 消息应该包含对象还是仅包含简单类型和字符串?
当使用 nservicebus 发送消息时,消息应该只包含简单的类型和字符串,还是可以包含您自己的对象?如果是这样,这些对象是否应该是没有任何行为的轻量级数据传输对象?
例如发送以下消息:
public class UserAuthenticatedMessage : IMessage {
public MyUserClass User { get; private set; }
public UserAuthenticatedMessage(MyUserClass user) {
User = user;
}
public object Value {
get { return User; }
}
}
其中 MyUserClass
不仅包含属性,还包含行为:
public class MyUserClass {
public int Id { get; set; }
public string Username { get; set; }
public bool ICheckSomething(string foo) {
}
}
这可以/一个坏主意吗?我们应该使用没有行为的 MyUserDTO 类吗?我们是否应该在消息中显式发送所有字段,然后在另一端将其转换为对象?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在消息中发送嵌套数据容器,即数据传输对象,但它们不应该有行为。
You can send nested data containers within your messages, i.e data transfer objects, but they shouldn't have behavior.