C# 尝试将上下文添加到Startup.cs时服务出现问题

C# 尝试将上下文添加到Startup.cs时服务出现问题,c#,asp.net-core-mvc,entity-framework-core,blazor,blazor-server-side,C#,Asp.net Core Mvc,Entity Framework Core,Blazor,Blazor Server Side,当我尝试迁移项目时,出现以下错误: An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Some services are not able to be constructed (Error while validating the service descriptor 'Se

当我尝试迁移项目时,出现以下错误:

An error occurred while accessing the Microsoft.Extensions.Hosting services. Continuing without the application service provider. Error: Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: AIR.Data.AmaxContext Lifetime: Scoped ImplementationType: AIR.Data.AmaxContext': A suitable constructor for type 'AIR.Data.AmaxContext' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.) (Error while validating the service descriptor 'ServiceType: AIR.Data.Services.SkuService Lifetime: Scoped ImplementationType: AIR.Data.Services.SkuService': A suitable constructor for type 'AIR.Data.AmaxContext' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.)
Unable to create an object of type 'AmaxContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
这是我的配置服务:

public void ConfigureServices(IServiceCollection services)
{
    services.AddRazorPages();
    services.AddServerSideBlazor();
    var builder = new MySqlConnectionStringBuilder(
        Configuration.GetConnectionString("AmaxContext")) {Password = Configuration["DbPassword"]};
    var connection = builder.ConnectionString;
    services.AddDbContext<AmaxContext>(options =>
        options.UseMySql(connection, builder =>
        {
            builder.EnableRetryOnFailure(5, TimeSpan.FromSeconds(10), null);
        }));
    services.AddScoped<SkuService>();
}
public void配置服务(IServiceCollection服务)
{
services.AddRazorPages();
AddServerSideBlazor();
var builder=new MySqlConnectionStringBuilder(
GetConnectionString(“AmaxContext”){Password=Configuration[“DbPassword”]};
var connection=builder.ConnectionString;
services.AddDbContext(选项=>
options.UseMySql(连接,生成器=>
{
builder.EnableRetryOnFailure(5,TimeSpan.FromSeconds(10),null);
}));
services.addScope();
}
这是我的服务:

using AIR.Data.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AIR.Data.Services
{
    public class SkuService
    {
        private AmaxContext _context;

        public SkuService(AmaxContext context)
        {
            _context = context;
        }

        public async Task<List<Core.SKU>> GetSkus()
        {
            return await _context.SKUs.ToListAsync();
        }
    }
}
使用AIR.Data.Models;
使用Microsoft.EntityFrameworkCore;
使用制度;
使用System.Collections.Generic;
使用System.Linq;
使用System.Threading.Tasks;
命名空间AIR.Data.Services
{
公营服务
{
私有AmaxContext\u上下文;
公共服务(AmaxContext上下文)
{
_上下文=上下文;
}
公共异步任务GetSkus()
{
return wait_context.SKUs.toListSync();
}
}
}

我对blazor还是一个新手,我正在尝试从mvc.NETCore迁移。我试图在C#discord和Blazor discord中找到帮助,但他们似乎也不知道原因。

结果,我的上下文的构造函数被设置为Protected而不是Public。问题解决了。感谢阅读。

事实证明,我的上下文的构造函数被设置为Protected而不是Public。问题解决了。谢谢你的阅读