Невозможно создать «dbcontext» типа «runtimetype»C#

Место общения программистов C#
Ответить
Anonymous
 Невозможно создать «dbcontext» типа «runtimetype»

Сообщение Anonymous »

Я получаю эту ошибку при миграции из фреймворта Entity: < /p>

Код: Выделить всё

dotnet ef migrations add initApp
< /code>

Невозможно создать «dbcontext» типа «runtimetype». Исключение «Невозможно разрешить службу для типа» microsoft.entityframeworkcore.dbcontextoptions`1 [cleanachitecture.security.infrastructure.context.securitydbcontext] ', пытаясь активировать' cleanachitecture.security.infrastruct.context.securitydbcontext '.'. был брошен во время попытки создать экземпляр. Для различных шаблонов, поддерживаемых во время дизайна, см. Https://go.microsoft.com/fwlink/?linkid=851728

DbContext
:

Код: Выделить всё

public sealed class SecurityDbContext(DbContextOptions options)
: DbContext(options), ISecurityDbContext
{
public DbSet securityMenus { get; set; }
public DbSet securityOptions { get; set; }
public DbSet securityProfiles { get; set; }
public DbSet securityUsers { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// base.OnModelCreating(modelBuilder);
modelBuilder.ApplyConfigurationsFromAssembly(typeof(SecurityDbContext).Assembly);
modelBuilder.HasDefaultSchema("public");
}

public override async Task SaveChangesAsync(CancellationToken cancellationToken = default)
{
int result = await base.SaveChangesAsync(cancellationToken);

return result;
}
}
< /code>
уровень инфраструктуры: < /p>
using CleanAchitecture.Security.Infrastructure.Context;
using CleanAchitecture.Security.Infrastructure.Interface;
using CleanAchitecture.Security.Infrastructure.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace CleanAchitecture.Security.Infrastructure
{
public static class DependencyInjection
{
public static IServiceCollection AddInfrastructure(
this IServiceCollection services,
IConfiguration configuration) =>
services
.AddDatabase(configuration)
.AddRegisterRepositories();

private static IServiceCollection AddDatabase(this IServiceCollection services, IConfiguration configuration)
{
string? connectionString = configuration.GetConnectionString("Database");

services.AddDbContext(
options => options.UseSqlServer(connectionString));

services.AddScoped(sp => sp.GetRequiredService());

return services;
}

private static IServiceCollection AddRegisterRepositories(this IServiceCollection services)
{
services.AddScoped();

return services;
}
}
}
< /code>
Startup
:
using CleanAchitecture.Security.Api;
using CleanAchitecture.Security.Api.Extensions;
using CleanAchitecture.Security.Application;
using CleanAchitecture.Security.Infrastructure;
using System.Reflection;

var builder = WebApplication.CreateBuilder(args);

// builder.Services.AddSwaggerGenWithAuth();

builder.Services.AddPresentation()
.AddApplication()
.AddInfrastructure(builder.Configuration);

builder.Services.AddEndpoints(Assembly.GetExecutingAssembly());

var app = builder.Build();

app.MapEndpoints();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
app.ApplyMigrations();
}

app.UseHttpsRedirection();

app.UseAuthentication();
app.UseAuthorization();

app.UseExceptionHandler();

await app.RunAsync();
< /code>
Please could you help me solve this error?

Подробнее здесь: https://stackoverflow.com/questions/797 ... untimetype
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»