MassTransit用元数据创建请求

发布于 2025-01-29 15:21:22 字数 622 浏览 4 评论 0 原文

我将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;
    }
}

I use MassTransit package into my project (clean Architecture).

In API-layer I write custom authorization filter and in HttpContext exist my CurrentUserInfo data.

then I Need UserInfo inside the Application Layer where IConsumer exist like Code below.

Now which way is better to do:

  • add metadata into my request client?
  • declare general class and inject it into implemented IConsumer class.
public class OptionCreateConsumer : IConsumer<OptionCreateRequest>
{
    private readonly IMapper _mapper;
    private readonly IUnitOfWork _unitOfWork;

    public OptionCreateConsumer(IMapper mapper, IUnitOfWork unitOfWork)
    {
        _mapper = mapper;
        _unitOfWork = unitOfWork;
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

錯遇了你 2025-02-05 15:21:22

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 the Token (which in your case, would be the UserInfo 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文