我正在尝试在“启动类”中添加范围,但由于某些原因,我会收到此错误。
无法从“服务”转换为“ System.Type”
无法从“ Iservice”转换为“ System.Type”
我还检查了是否在所有其他类中正确注入了服务。
这是代码
public class Startup
{
private readonly IService Iservice;
private readonly Service service;
public Startup(IConfiguration configuration, IService Iservice, Service service)
{
Configuration = configuration;
this.Iservice = Iservice;
this.service = service;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext<DbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("Connectionstring")));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
// This is where I get the error
services.AddScoped(Iservice, service);
}
这似乎是一个初学者的问题,所以很抱歉。