开发者

Should nServiceBus messages contain objects or just simple types and strings?

开发者 https://www.devze.com 2023-03-16 02:14 出处:网络
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 ob

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) {

    }
}

I开发者_如何学Gos 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消