Azure功能中的MediaTr命令ServiceBustrigger

发布于 2025-01-23 18:51:34 字数 962 浏览 4 评论 0 原文

使用一些引用,我使用干净的体系结构创建了 azure函数应用程序,项目结构看起来像这样:

“ nofollow noreferrer”> “在此处。基本上,我想调用 MediaTr 命令 createProductCommand 此功能触发器内。因此,只要有消息将消息推入服务总线队列时,我就可以使用此 MediaTr 命令将其保存到SQL数据库中。 createProductCommand 具有EF核心实现。

public class SaveProductDataToDatabase
    {
        private readonly IMediator _mediator;

        public SaveProductDataToDatabase(IMediator mediator)
        {
            _mediator = mediator;
        }

        [FunctionName("SaveProductDataToDatabase")]
        public void Run([ServiceBusTrigger("product-data-dev-01", Connection = "ServiceBusConnectionString")] string myQueueItem, ILogger log)
        {
            log.LogInformation($"Processed message: {myQueueItem}");
        }
    }

我不确定如何在此功能触发器内使用 createProductCommand 。请帮忙。

Using some references, I have created the Azure Function App with Clean Architecture and the Project structure looks like this:

enter image description here

My Azure Function is of the type Service Bus Queue Trigger. Basically, I want to Call MediatR command CreateProductCommand inside this function trigger. So that, whenever there is a message pushed into Service bus Queue, I can read that and save that into SQL database using this MediatR command. CreateProductCommand has EF Core implementation.

public class SaveProductDataToDatabase
    {
        private readonly IMediator _mediator;

        public SaveProductDataToDatabase(IMediator mediator)
        {
            _mediator = mediator;
        }

        [FunctionName("SaveProductDataToDatabase")]
        public void Run([ServiceBusTrigger("product-data-dev-01", Connection = "ServiceBusConnectionString")] string myQueueItem, ILogger log)
        {
            log.LogInformation(
quot;Processed message: {myQueueItem}");
        }
    }

I'm not sure how to use the CreateProductCommand inside this function trigger. Please help.

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

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

发布评论

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

评论(1

书间行客 2025-01-30 18:51:34

在功能之上添加MediaTR命令处理程序是冗余的,因为功能本身已经是一个处理程序,并且是一小部分工作。函数通常负责将责任封装在功能代码中。除非您的功能有多个职责,否则不必要。

Adding MediatR command handler on top of a function is redundant as function is already a handler in itself and a small unit of work. A function has a single responsibility usually that responsibility is encapsulated in the function code. Unless your function has multiple responsibilities, which it shouldn’t, MediatR is unnecessary.

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