enter image description here

program.cs:

var builder = WebApplication.CreateBuilder(args);
var connectionString = builder.Configuration.GetConnectionString("Default");

// Add services to the container.
builder.Services.AddDbContext<GerenciadorContext>(opts =>
{
    opts.UseMySql(connectionString,ServerVersion.AutoDetect(connectionString));
});

builder.Services.AddIdentity<IdentityUser,IdentityRole>()
    .AddEntityFrameworkStores<GerenciadorContext>();

builder.Services.AddTransient<IUserDao, UserDao>();

builder.Services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
builder.Services.AddControllers();

// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

As soon as I make a request it returns this error, I don't know if it's something in .NET 8

1

There are 1 best solutions below

1
hs.jalilian On

Please make sure to change the registration from

builder.Services.AddTransient<IUserDao, UserDao>();

to

builder.Services.AddScoped<IUserDao, UserDao>();

With this modification, your problem should be resolved.