【问题标题】:MVC n-Tier architecuture project dependenciesMVC n-Tier 架构项目依赖项
【发布时间】:2017-11-08 13:04:24
【问题描述】:

我的 mvc5 项目具有以下结构。

我的 DAL 层中有 DbContext 文件,“实体”层中有“ApplicationUserManager”类,如下所示。

“实体”层中的“ApplicationUserManager”类具有以下代码,即。

public class ApplicationUserManager : UserManager<ApplicationUser>
    {
        public ApplicationUserManager(IUserStore<ApplicationUser> store)
              : base(store)
        {
        }
        public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
        {
            var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));



Here, I am getting error :
1. The type or namespace name 'ApplicationDbContext' could not be found (are you missing a using directive or an assembly reference?
2. The type or namespace name 'DAL' does not exist in the namespace 'MVCFinal' (are you missing an assembly reference?

现在,如果我向实体添加对 DAL 层的引用,那么很多其他东西都会被破坏。 如何纠正实体层中的此“ApplicationDbContext”错误。 引用 n 层中的层的正确方法是什么。

谢谢。

【问题讨论】:

    标签: asp.net-mvc entity-framework n-tier-architecture


    【解决方案1】:

    问题是你有一个不允许也不推荐的循环依赖。

    DAL 依赖于实体并且实体依赖于 DAL

    考虑将 ApplicationDbContext 移至公共库,这样您就不必在实体库中引用 DAL 库。

    【讨论】:

    • 是的,我面临循环依赖错误,但我在某处了解到 AppDbContext 应该在 DAL 中,因为它与数据访问有关。
    • @user1829056,您也可以将 DAL 使用的一些实体类移动到公共库中,并删除它对实体的依赖
    • 但在这种情况下,我的实体(域类)将分散在多个项目中。我想把它们放在一个项目中。
    猜你喜欢
    • 1970-01-01
    • 2013-01-30
    • 2021-05-27
    • 1970-01-01
    • 2014-03-19
    • 1970-01-01
    • 1970-01-01
    • 2020-07-24
    • 2010-10-01
    相关资源
    最近更新 更多