小编use*_*017的帖子

.NET Core 控制台应用程序 Mediatr 命令处理程序不会被调用

我面临一个问题,即没有调用 Mediatr 命令处理程序。我有以下解决方案结构。

Project.sln -> Application layer (.NET standard class library) -> Jobs (.NET standard class library) -> Job Server (.NET Core console app)

这个想法是作业服务器使用调度程序(Quartz.NET)来执行作业。实际的业务逻辑在应用层。应用层使用 CQRS 模式,使用 Mediatr 进行连接。我正在使用 Microsoft 依赖注入库。

作业服务器Main方法(带 DI 代码):

public class Program
{
    static ManualResetEvent _quitEvent = new ManualResetEvent(false);

    static void Main(string[] args)
    {
        Console.WriteLine("Job Server started");

        //DI setup
        var serviceProvider = new ServiceCollection()
            .AddQuartz()
            .AddTransient<InitializeJobServer>()
            .AddTransient<ProcessAdRssFeedsJob>()
            .AddScoped<IConfigService, ConfigService>()
            .AddScoped<IRssService, RssService>()
            .AddScoped<IBaseService, BaseService>()
            .AddMediatR(typeof(ProcessAdSectionsRssCommand).GetType().Assembly)
            .AddDbContext<MyDbContext>(options =>
                options.UseNpgsql("xxx"))
            .AddMemoryCache()
            .BuildServiceProvider();

        Console.CancelKeyPress += (sender, eArgs) …
Run Code Online (Sandbox Code Playgroud)

.net c# console dependency-injection mediatr

5
推荐指数
1
解决办法
9290
查看次数

标签 统计

.net ×1

c# ×1

console ×1

dependency-injection ×1

mediatr ×1