В моем методе расширения я пытаюсь добавить службы идентификации:
using Domain.Entities;
using Infrastructure.Persistence;
using Infrastructure.Seeders;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Infrastructure.Extensions;
///
/// Provides extension methods for registering infrastructure services.
///
public static class ServiceCollectionExtensions
{
public static void AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
{
#region DB Connection
string? connectionString = configuration.GetConnectionString("DummyDbName");
services.AddDbContext(options => options.UseNpgsql(connectionString));
#endregion
#region Register Services
services.AddScoped();
#endregion
services.AddIdentity()
.AddEntityFrameworkStores()
.AddDefaultTokenProviders();
}
}
Когда я пытаюсь это сделать, я получаю сообщение об ошибке, упомянутое в заголовке.
Я видел здесь несколько вопросов, связанных с этим, но большинство из них рекомендуется для установки:
Microsoft.AspNetCore.Identity;
пакет, который устарел (думаю, это уже часть чего-то другого).
Странно, что в моем Program.cs< /code> я могу без проблем использовать метод AddIdentity.
Program.cs:
using Infrastructure.Extensions;
using Infrastructure.Seeders;
var builder = WebApplication.CreateBuilder(args);
{
#region Service Collection Extensions
builder.Services.AddInfrastructure(builder.Configuration);
#endregion
builder.Services.AddControllers();
//builder.Services.AddIdentity This would work.
}
var app = builder.Build();
{
// Create Scope, run seeders
var scope = app.Services.CreateScope();
var roleSeeder = scope.ServiceProvider.GetRequiredService();
await roleSeeder.SeedRolesAsync();
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... ddidentity
IServiceCollection не содержит определения для AddIdentity. ⇐ C#
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение