Diogo,
Estou usando os pacotes do ".Net 6" e recriei o arquivo startup.cs.
Pacotes:
UserDbContext:
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace UsuariosApi.Data;
public class UserDbContext : IdentityDbContext<IdentityUser<int>, IdentityRole<int>, int>
{
public UserDbContext(DbContextOptions<UserDbContext> opt) : base(opt)
{
}
}
Startup.cs:
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using UsuariosApi.Data;
namespace UsuariosApi.Startup;
internal class Startup : IStartup
{
#region Propriedades
public IConfiguration Configuration { get; }
#endregion
#region Construtores
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
#endregion
#region Métodos
public void ConfigureServices(IServiceCollection services)
{
//Serviço de Banco de Dados
services.AddDbContext<UserDbContext>(options =>
{
options.UseMySQL(Configuration.GetConnectionString("UsuarioConnection"));
});
//Utilizar os Identities:
services.AddIdentity<IdentityUser<int>, IdentityRole<int>>()
.AddEntityFrameworkStores<UserDbContext>();
//Serviço Automapper inicializado:
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
services.AddControllers();
services.AddEndpointsApiExplorer();
services.AddSwaggerGen();
}
public void Configure(WebApplication app, IWebHostEnvironment environment)
{
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
}
#endregion
}
Program.cs:
using UsuariosApi.Startup;
WebApplicationBuilder? _ = WebApplication.CreateBuilder(args).UseStartup<Startup>();
[]'s,
Fabio I.