Dependency injection 如何在.NETCore2.2中的服务类构造函数中传递具体类型

Dependency injection 如何在.NETCore2.2中的服务类构造函数中传递具体类型,dependency-injection,c#-7.0,.net-core-2.2,Dependency Injection,C# 7.0,.net Core 2.2,我在犯错误 在尝试激活“DatabaseConsumer.DatabaseScheduler”时,无法解析类型“System.Action1[DatabaseConsumer.MyFooClass]”的服务 我的服务类如下面的示例所示,我需要在构造函数中包含Action-Action、TType-objTType、string-cron,另外,FooService实现IHostedService public class DatabaseScheduler<TType> :

我在犯错误

在尝试激活“DatabaseConsumer.DatabaseScheduler”时,无法解析类型“System.Action
1[DatabaseConsumer.MyFooClass]”的服务

我的服务类如下面的示例所示,我需要在构造函数中包含Action-Action、TType-objTType、string-cron,另外,FooService实现IHostedService

    public class DatabaseScheduler<TType> : FooService
    {
        protected override string CronSchedule { get; set; }
        private Action<TType> _action;
        TType _obj;

        public DatabaseScheduler(IServiceScopeFactory serviceScopeFactory, Action<TType> action, TType objTType, string cron) : base(serviceScopeFactory, cron)
        {
            _action = action;
            CronSchedule = cron;
            _obj = objTType;
        }

        public override Task ProcessInScopeService(IServiceProvider serviceProvider)
        {
            //Call the ProcessIntegrationMessages()
            _action.Invoke(_obj);
            return Task.CompletedTask;
        }
    }
公共类数据库调度器:FooService
{
受保护的重写字符串CronSchedule{get;set;}
私人行动;
t类型_obj;
公共数据库调度器(IServiceScopeFactory serviceScopeFactory,Action Action,TType objTType,string cron):基本(serviceScopeFactory,cron)
{
_行动=行动;
CronSchedule=cron;
_obj=objTType;
}
公共覆盖任务ProcessInScopeService(IServiceProvider服务提供程序)
{
//调用ProcessIntegrationMessages()函数
_action.Invoke(_obj);
返回Task.CompletedTask;
}
}
在Startup.cs中,将我的服务类添加到IServiceCollection服务

 services.AddSingleton(typeof(Microsoft.Extensions.Hosting.IHostedService), typeof(DatabaseScheduler<MyFooClass>));
services.AddSingleton(typeof(Microsoft.Extensions.Hosting.IHostedService)、typeof(DatabaseScheduler));

在哪里添加
操作
服务?@paolomorgado方法ProcessInScopeService()应该是
服务。添加……