hopefully not a horribly foolish refactoring
This commit is contained in:
parent
59d660165f
commit
1ecaf64dea
82 changed files with 782 additions and 398 deletions
41
Femto.Common/Infrastructure/Outbox/OutboxServiceExtension.cs
Normal file
41
Femto.Common/Infrastructure/Outbox/OutboxServiceExtension.cs
Normal file
|
@ -0,0 +1,41 @@
|
|||
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<TContext>(
|
||||
this IServiceCollection services,
|
||||
Func<IServiceProvider, TContext>? contextFactory = null
|
||||
)
|
||||
where TContext : DbContext, IOutboxContext
|
||||
{
|
||||
|
||||
services.AddSingleton<IOutboxMessageMapping, ClrTypenameMessageMapping>();
|
||||
|
||||
services.AddScoped<IOutboxContext>(c =>
|
||||
contextFactory?.Invoke(c) ?? c.GetRequiredService<TContext>()
|
||||
);
|
||||
|
||||
services.AddScoped<Outbox<TContext>>();
|
||||
|
||||
services.AddQuartz(q =>
|
||||
{
|
||||
var jobKey = JobKey.Create(nameof(OutboxProcessor<TContext>));
|
||||
|
||||
q.AddJob<OutboxProcessor<TContext>>(jobKey)
|
||||
.AddTrigger(trigger =>
|
||||
trigger
|
||||
.ForJob(jobKey)
|
||||
.WithSimpleSchedule(schedule =>
|
||||
schedule.WithIntervalInSeconds(1).RepeatForever()
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue