1
0
mirror of synced 2024-12-02 17:57:18 +01:00
GC-local-server-rewrite/Application/DependencyInjection.cs

77 lines
3.0 KiB
C#
Raw Normal View History

using System.Reflection;
2023-02-09 10:25:42 +01:00
using Application.Common.Behaviours;
using Application.Game.Card;
using Application.Jobs;
using MediatR;
using Microsoft.Extensions.DependencyInjection;
using Quartz;
namespace Application;
public static class DependencyInjection
{
public static IServiceCollection AddApplication(this IServiceCollection services, int refreshIntervalHours = 24)
{
services.AddMediatR(configuration => configuration.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
2023-02-09 10:25:42 +01:00
services.AddScoped<ICardDependencyAggregate, CardDependencyAggregate>();
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(UnhandledExceptionBehaviour<,>));
services.AddQuartz(q =>
{
q.UseMicrosoftDependencyInjectionJobFactory();
2023-02-16 08:26:13 +01:00
q.AddJob<UpdatePlayNumRankJob>(options => options.WithIdentity(UpdatePlayNumRankJob.KEY));
q.AddTrigger(options =>
{
2023-02-16 08:26:13 +01:00
options.ForJob(UpdatePlayNumRankJob.KEY)
.WithIdentity("UpdatePlayNumRankJob-trigger")
.StartNow()
.WithSimpleSchedule(x =>
{
x.WithIntervalInHours(refreshIntervalHours).RepeatForever();
});
});
2023-02-16 08:26:13 +01:00
q.AddJob<UpdateGlobalScoreRankJob>(options => options.WithIdentity(UpdateGlobalScoreRankJob.KEY));
q.AddTrigger(options =>
{
options.ForJob(UpdateGlobalScoreRankJob.KEY)
.WithIdentity("UpdateGlobalScoreRankJob-trigger")
.StartNow()
.WithSimpleSchedule(x =>
{
x.WithIntervalInHours(refreshIntervalHours).RepeatForever();
2023-02-16 08:26:13 +01:00
});
});
q.AddJob<UpdateMonthlyScoreRankJob>(options => options.WithIdentity(UpdateMonthlyScoreRankJob.KEY));
q.AddTrigger(options =>
{
options.ForJob(UpdateMonthlyScoreRankJob.KEY)
.WithIdentity("UpdateMonthlyScoreRankJob-trigger")
.StartNow()
.WithSimpleSchedule(x =>
{
x.WithIntervalInHours(refreshIntervalHours).RepeatForever();
2023-02-16 08:26:13 +01:00
});
});
2023-02-22 18:15:53 +01:00
q.AddJob<MaintainNullValuesJob>(options => options.WithIdentity(MaintainNullValuesJob.KEY));
2023-02-16 08:26:13 +01:00
q.AddTrigger(options =>
{
2023-02-22 18:15:53 +01:00
options.ForJob(MaintainNullValuesJob.KEY)
.WithIdentity("MaintainNullValuesJob-trigger")
2023-02-16 08:26:13 +01:00
.StartNow()
.WithSimpleSchedule(x =>
{
x.WithIntervalInHours(refreshIntervalHours).RepeatForever();
2023-02-16 08:26:13 +01:00
});
});
});
services.AddQuartzHostedService(options =>
{
options.WaitForJobsToComplete = true;
});
return services;
}
}