Skip to content

Commit

Permalink
fix(tasks): fix get executor types
Browse files Browse the repository at this point in the history
  • Loading branch information
pogromistik committed Oct 12, 2023
1 parent d5a2ea8 commit f73104e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Sitko.Core.Tasks/TasksModule.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using FluentValidation;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Sitko.Core.App;
using Sitko.Core.Repository;
using Sitko.Core.Tasks.BackgroundServices;
Expand Down Expand Up @@ -31,7 +32,13 @@ public override void ConfigureServices(IApplicationContext applicationContext, I
{
foreach (var assembly in startupOptions.Assemblies)
{
types.AddRange(assembly.ExportedTypes.Where(type => typeof(ITaskExecutor).IsAssignableFrom(type)));
types.AddRange(assembly.ExportedTypes.Where(type => typeof(ITaskExecutor).IsAssignableFrom(type) &&
!type.IsAbstract &&
typeof(TBaseTask).IsAssignableFrom(type
.GetInterfaces()
.First(i => i.IsGenericType &&
typeof(ITaskExecutor).IsAssignableFrom(i))
.GenericTypeArguments.First())));
}
}

Expand All @@ -56,9 +63,9 @@ public override void ConfigureServices(IApplicationContext applicationContext, I
services.Scan(selector => selector.FromTypes(executors.Select(e => e.ExecutorType)).AsSelfWithInterfaces()
.WithScopedLifetime());

services.AddScoped<ITaskScheduler, TTaskScheduler>();
services.TryAddScoped<ITaskScheduler, TTaskScheduler>();

services.AddScoped<TasksManager>();
services.TryAddScoped<TasksManager>();
services.AddTransient<IRepository<TBaseTask, Guid>, TasksRepository<TBaseTask, TDbContext>>();
services.AddTransient<ITaskRepository<TBaseTask>, TasksRepository<TBaseTask, TDbContext>>();
services.AddHostedService<TasksCleaner<TBaseTask, TOptions>>();
Expand Down

0 comments on commit f73104e

Please sign in to comment.