MVC在大型项目中采用EF解决方案设计

时间:2012-09-24 04:37:19

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

我可以使用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();

模型数据库商业逻辑是解决方案中的不同项目。

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

1 个答案:

答案 0 :(得分:1)

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

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

然后看一下使用Repository / UnitOfWork模式和Entity Framework,另一篇文章:

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

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

http://mvcbootstrap.codeplex.com