Код: Выделить всё
dotnet ef database update --context IdentityDataContext
Код: Выделить всё
Build started...
Build succeeded.
Unable to create an object of type 'IdentityDataContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
Код: Выделить всё
public static class DependencyInjection
{
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
{
var connectionString = configuration.GetConnectionString("LoginPostgres");
services.AddDbContext(options =>
{
options.UseNpgsql(connectionString);
});
services.AddDbContext(options =>
{
options.UseNpgsql(connectionString);
});
services.AddIdentity(options =>
{
options.Password.RequireDigit = false;
options.Password.RequiredLength = 4;
options.Password.RequireNonAlphanumeric = false;
options.Password.RequireUppercase = false;
options.Password.RequireLowercase = false;
options.SignIn.RequireConfirmedAccount = false;
options.User.RequireUniqueEmail = true;
}).AddEntityFrameworkStores().AddDefaultTokenProviders();
services.AddScoped();
services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies());
services.AddScoped(typeof(IRepositorioGenerico), typeof(RepositorioGenerico));
services.AddSingleton();
services.AddScoped();
services.AddScoped();
services.AddScoped();
services.AddRazorPages();
services.AddHttpContextAccessor();
return services;
}
}
Код: Выделить всё
using Login.Domain.Entities;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Login.Infrastructure.Data.Context
{
public class IdentityDataContext : IdentityDbContext
{
public IdentityDataContext(DbContextOptions options) : base(options)
{
}
}
}
Заранее спасибо за помощь!
Код: Выделить всё
Microsoft.EntityFrameworkCore.Design.OperationException: Unable to create an object of type 'IdentityDataContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
---> System.InvalidOperationException: Unable to resolve service for type 'Microsoft.EntityFrameworkCore.DbContextOptions`1[Login.Infrastructure.Data.Context.IdentityDataContext]' while attempting to activate 'Login.Infrastructure.Data.Context.IdentityDataContext'.
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ConstructorMatcher.CreateInstance(IServiceProvider provider)
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.CreateInstance(IServiceProvider provider, Type instanceType, Object[] parameters)
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetServiceOrCreateInstance(IServiceProvider provider, Type type)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.c__DisplayClass21_4.b__13()
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.c__DisplayClass21_4.b__13()
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(Func`1 factory)
at Microsoft.EntityFrameworkCore.Design.Internal.DbContextOperations.CreateContext(String contextType)
at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String connectionString, String contextType)
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.c__DisplayClass0_0.b__0()
at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)
Unable to create an object of type 'IdentityDataContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
Подробнее здесь: https://stackoverflow.com/questions/787 ... atacontext
Мобильная версия