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