'envelope' 对象有什么用?

What are 'envelope' objects used for?

查看 RealWorld example apps 的代码,我看到它们将对象包装在 "Envelope" 对象中,如下所示:

namespace Conduit.Features.Users
{
    public class User
    {
        public string Username { get; set; }

        public string Email { get; set; }

        public string Bio { get; set; }

        public string Image { get; set; }

        public string Token { get; set; }
    }


    public class UserEnvelope
    {
        public UserEnvelope(User user)
        {
            User = user;
        }

        public User User { get; set; }
    }
}

为什么需要这个?这是 CQRS 模式的一部分吗?如果是这样,为什么不直接在 Command 或 Query 对象上添加属性,或者 return 只是 User 对象本身?如果不是,这个模式的名称是什么?

因此您可以传递元数据而不会弄乱业务实体。