Skip to content

Commit

Permalink
😊 修复 在扫描类型并自动注册 BackgroundService 时没有排除抽象类和接口问题 #IBA6IU
Browse files Browse the repository at this point in the history
  • Loading branch information
MonkSoul committed Dec 10, 2024
1 parent 519729c commit c178c04
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static IServiceCollection AddInjectWithUnifyResult<TUnifyResultProvider>(
public static IServiceCollection AddAppHostedService(this IServiceCollection services)
{
// 获取所有 BackgroundService 类型,排除泛型主机
var backgroundServiceTypes = App.EffectiveTypes.Where(u => typeof(IHostedService).IsAssignableFrom(u) && u.Name != "GenericWebHostService");
var backgroundServiceTypes = App.EffectiveTypes.Where(u => !u.IsAbstract && !u.IsInterface && typeof(IHostedService).IsAssignableFrom(u) && u.Name != "GenericWebHostService");
var addHostServiceMethod = typeof(ServiceCollectionHostedServiceExtensions).GetMethods(BindingFlags.Static | BindingFlags.Public)
.Where(u => u.Name.Equals("AddHostedService") && u.IsGenericMethod && u.GetParameters().Length == 1)
.FirstOrDefault();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static IServiceCollection AddInjectWithUnifyResult<TUnifyResultProvider>(
public static IServiceCollection AddAppHostedService(this IServiceCollection services)
{
// 获取所有 BackgroundService 类型,排除泛型主机
var backgroundServiceTypes = App.EffectiveTypes.Where(u => typeof(IHostedService).IsAssignableFrom(u) && u.Name != "GenericWebHostService");
var backgroundServiceTypes = App.EffectiveTypes.Where(u => !u.IsAbstract && !u.IsInterface && typeof(IHostedService).IsAssignableFrom(u) && u.Name != "GenericWebHostService");
var addHostServiceMethod = typeof(ServiceCollectionHostedServiceExtensions).GetMethods(BindingFlags.Static | BindingFlags.Public)
.Where(u => u.Name.Equals("AddHostedService") && u.IsGenericMethod && u.GetParameters().Length == 1)
.FirstOrDefault();
Expand Down

0 comments on commit c178c04

Please sign in to comment.