我面临一个问题,即没有调用 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)