Я получаю эту ошибку при попытке перенести проект:
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>();
}
Это моя служба skuservice:
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();
}
}
}
Я все еще новичок в Blazor и пытаюсь перейти с ядра mvc. net. Я пытался найти помощь в разногласиях C# и Blazor, но они не могут понять, почему тоже.