fix: registration

This commit is contained in:
2024-03-10 18:20:41 +07:00
parent 5d80c6351c
commit 6af885a4f8
6 changed files with 63 additions and 23 deletions

View File

@@ -6,13 +6,13 @@ public class HostedServiceRegistrator
{
public void RegisterHostedService(IServiceCollection services, Type hostedServiceType)
{
Type servicesType = typeof(HostedServiceRegistrator);
MethodInfo methodInfo = servicesType.GetMethod("AddHostedService");
MethodInfo genericMethod = methodInfo.MakeGenericMethod(hostedServiceType);
var servicesType = typeof(HostedServiceRegistrator);
var methodInfo = servicesType.GetMethod(nameof(AddHostedService));
var genericMethod = methodInfo.MakeGenericMethod(hostedServiceType);
genericMethod.Invoke(this, new object[] { services });
}
// Needed as a work-arround because we can't call the extension method with reflection.
public IServiceCollection AddHostedService<THostedService>(IServiceCollection services)
where THostedService : class, IHostedService =>
services.AddHostedService<THostedService>();