using System.Reflection; using Femto.Common.Attributes; using MediatR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; using Quartz; namespace Femto.Common.Infrastructure.Outbox; public static class OutboxServiceExtension { public static void AddOutbox( this IServiceCollection services, Func? contextFactory = null ) where TContext : DbContext, IOutboxContext { services.AddSingleton(); services.AddScoped(c => contextFactory?.Invoke(c) ?? c.GetRequiredService() ); services.AddScoped>(); services.AddQuartz(q => { var jobKey = JobKey.Create(nameof(OutboxProcessor)); q.AddJob>(jobKey) .AddTrigger(trigger => trigger .ForJob(jobKey) .WithSimpleSchedule(schedule => schedule.WithIntervalInSeconds(1).RepeatForever() ) ); }); } }