【问题标题】:MVC with EF solution design in large projects大型项目中带有 EF 解决方案设计的 MVC
【发布时间】:2012-09-15 13:14:29
【问题描述】:

我可以使用 MVC 解决方案的默认设计。例如控制器:

public class ProductController : Controller
   {
       private Entities db = new Entities();

       public ViewResult Details( int id )
          {
              Product product = db.Products.Single( p => p.ID == id );
              return View( product );
          }
    }

但是我在一些大型项目中看到,调用任何方法,他们只使用服务,例如

public class ProductController : Controller<ISomeService>
{
 public ViewResult Details( int id )
    {
       Product product = MyService.GetProductById();
       return View( product );
    }
}

并且不使用控制器中的数据库实例,例如:

private Entities db = new Entities();

模型DB业务逻辑是解决方案中的不同项目。

我可以从哪里了解任何示例中的这种结构? (抱歉英语不好)

【问题讨论】:

    标签: asp.net-mvc-3 wcf design-patterns projects-and-solutions business-logic-layer


    【解决方案1】:

    我会看看在 ASP.NET MVC 中使用依赖注入,这里有一篇关于这个主题的文章:

    http://weblogs.asp.net/shijuvarghese/archive/2010/04/30/dependency-injection-in-nerddinner-app-using-ninject.aspx

    然后看看使用 Repository/UnitOfWork 模式与实体框架,另一篇文章:

    http://www.codeproject.com/Tips/309753/Repository-Pattern-with-Entity-Framework-4-1-and-C

    如果您对自己编写所有这些代码不感兴趣,您可以在此处使用,或者至少看看它是如何完成的:

    http://mvcbootstrap.codeplex.com

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多