【问题标题】:How to get methods from other project in the same solution如何在同一解决方案中从其他项目获取方法
【发布时间】:2013-09-21 16:03:20
【问题描述】:

我有这个结构:

-Main [solution]
       -MainApp [project]
           -Models [folder]
               -DbContext.cs
           -Controler  [folder]
               -TestControler.cs

       -MainAppRepository [project]
           -SomeClass.cs

这是我的 MVC 应用程序。我想在我的SomeClass.cs 中访问来自DbContext.cs 的字段,并在TestControler.cs 中访问来自SomeClass.cs 的方法。

我怎样才能做到这一点? 我试过Add dependences函数,但没有任何结果..

【问题讨论】:

  • 这不是循环依赖吗?
  • 我强烈建议您将 DbContext 从这两个解决方案中移出,并移到第三个 类库 项目中。
  • @ErikPhilips,我为什么要这样做?我现在知道这是导致circular dependency 情况的原因,但我问的是一般情况 - 为什么我应该将我的ModelsDbContextRepositories 移动到单独的项目中?而不是将它们存储在主项目中?我尝试学习 IoC 和 DI 模式,这对我来说根本无法理解。问候!

标签: c# .net visual-studio visual-studio-2012


【解决方案1】:

您是否也导入了命名空间(“使用 MainApp”)?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-10
    相关资源
    最近更新 更多