小编Mic*_*ers的帖子

在n层架构中使用带有依赖注入的ApplicationDbContext

我有一个使用Asp.Net MVC Core 2.1构建的3层(Presentation - Business - Data)应用程序

在我的Presentation层中,我有一个ApplicationDbContext类,它实例化并填充测试数据库:

public class ApplicationDbContext : IdentityDbContext
{
    public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
        : base(options)
    {
    }

    protected override void OnModelCreating(ModelBuilder builder)
    {
        base.OnModelCreating(builder);
        SeedData(builder);
    }

    // Database Tables
    public DbSet<Customer> Customers { get; set; }
    public DbSet<Ingredient> Ingredients { get; set; }
    public DbSet<Order> Orders { get; set; }
    public DbSet<OrderDetail> OrderDetails { get; set; }
    public DbSet<Pizza> Pizzas { get; set; }
    public DbSet<PizzaIngredient> PizzaIngredients { get; set; }

    // Fill Database with …
Run Code Online (Sandbox Code Playgroud)

c# dependency-injection layered dbcontext asp.net-core

1
推荐指数
1
解决办法
175
查看次数