19 lines
693 B
C#
19 lines
693 B
C#
using System.Reflection;
|
|
|
|
namespace InServiceQue.Sample;
|
|
|
|
public class HostedServiceRegistrator
|
|
{
|
|
public void RegisterHostedService(IServiceCollection services, Type hostedServiceType)
|
|
{
|
|
var servicesType = typeof(HostedServiceRegistrator);
|
|
var methodInfo = servicesType.GetMethod(nameof(AddHostedService));
|
|
var genericMethod = methodInfo.MakeGenericMethod(hostedServiceType);
|
|
|
|
genericMethod.Invoke(this, new object[] { services });
|
|
}
|
|
|
|
public IServiceCollection AddHostedService<THostedService>(IServiceCollection services)
|
|
where THostedService : class, IHostedService =>
|
|
services.AddHostedService<THostedService>();
|
|
} |