MassTransit用元数据创建请求
我将MassTransit软件包用于我的项目(干净体系结构)。
在API层中,我编写自定义授权过滤器,在 httpcontext
中存在我的CurrentUserInfo数据。
然后,我需要在应用程序层中的userInfo,其中iConsumer存在下面的代码。
现在最好做哪种方法:
- 将元数据添加到我的请求客户端中?
- 声明通用类并将其注入实现的Iconsumer类。
public class OptionCreateConsumer : IConsumer<OptionCreateRequest>
{
private readonly IMapper _mapper;
private readonly IUnitOfWork _unitOfWork;
public OptionCreateConsumer(IMapper mapper, IUnitOfWork unitOfWork)
{
_mapper = mapper;
_unitOfWork = unitOfWork;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 scoped filter 样本中,您可以看到如何使用发送/发布和捕获过滤器来捕获过滤器并将
令牌
对象从请求客户端传递给消费者。tokenactionFilter
是也可以范围范围,将传入的数据拉到令牌
(在您的情况下为userInfo
对象。 =“ https://github.com/masstransit/sample-scopedfilters/blob/master/src/src/webapi/startup.cs#l32” rel =“ nofollow noreferrer”> filters 使用用于MassTransit的forters 用于补充向标题的数据,以便下游消费者能够使用该标头来初始化令牌(或为您的方案使用UserInfo)。
In the scoped filter sample, you can see how Send/Publish and Consume filters are used to capture and pass a
Token
object from the request client to the consumer.The
TokenActionFilter
is added so that it is scoped as well, pulling the incoming data into theToken
(which in your case, would be theUserInfo
object.The filters configured for MassTransit are used to add that data to the headers, so that downstream consumers are able to use that header to initialize the Token (or UserInfo for your scenario).