且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将 MediatR PublishStrategy 添加到现有项目

更新时间:2023-02-17 07:53:23

您可以扩展 Publish 创建一个定义您自己的 DefaultStrategy 的子类:

You could extend Publish creating a subclass defining your own DefaultStrategy:

public class MyPublisher : Publisher
{
    public MyPublisher(ServiceFactory serviceFactory) : base(serviceFactory)
    {
        DefaultStrategy = PublishStrategy.ParallelNoWait;
    }
}

因此,您可以通过调用基本构造函数并覆盖初始化 DefaultStrategy 成员的值来保持 Mediatr 中的源代码完整.

So you keep the source code intact from Mediatr by calling the base constructor and overriding the value with which the DefaultStrategy member was initialized.

当然,在您的 DI 容器中注册您的自定义 MyPublisher 而不是 Publisher:

And, of course, register your custom MyPublisher in your DI Container instead of Publisher:

services.AddSingleton<MyPublisher>();