为工作单元和存储库模式,为大型项目非常有用吗? [英] Is Unit Of Work and Repository Patterns very useful for big projects?

查看:502
本文介绍了为工作单元和存储库模式,为大型项目非常有用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用ASP.NET Web表单+ EF4一个新的Web项目。我试图用下面这个教程工作模式的单位申请一个存储库模式:的 http://www.dotnetage.com/publishing/home/2011/07/05/6883/the-repository -pattern与 - EF-代码先dependeny注射式-ASP净mvc3.html

I'm starting a new web project using ASP.NET Webforms + EF4. I'm trying to apply a repository pattern with a unit of work pattern following this tutorial : http://www.dotnetage.com/publishing/home/2011/07/05/6883/the-repository-pattern-with-ef-code-first-dependeny-injection-in-asp-net-mvc3.html

我觉得我有这个想法,但我的问题是,当我创建模型中的一个新的对象,难道我还必须定义在单位工作IDALContext那个对象?这不是快速发展的handbreak?此外,如果你有mmultiple开发人员的工作,如果你不希望其他开发者看到你的DAL,你如何管理呢?因为在这种模式我的理解,当你在模型中创建一个新的对象,你也可以在IDALContext定义它本教程。对不起,我本很困惑。

I think i got the idea but my question is that, when i create a new object in the model, do i also have to define that object in IDALContext of the Unit Of Work? Isn't that a handbreak for rapid development? Also if you work with mmultiple developers and if you don't want other developers to see your DAL, how can you manage this? Because in this pattern as i understand, when you create a new object in the model you also have to define it in the IDALContext for this tutorial. Sorry i'm so confused by this.

感谢

推荐答案

Martin Fowler的描述作为仓库的角色:一个存储库中的域和数据映射层之间的中间,像个内存中的域对象集。什么实体框架4.1自曝在这个意义上的存储库。此外,英孚已经建工作的统一。所以我的建议是忽略你在你的问题中提到的博客文章。

Martin Fowler describes the repository's role as: "A Repository mediates between the domain and data mapping layers, acting like an in-memory domain object collection". What Entity Framework 4.1 exposes is a repository in that sense. Also EF has a unity of work built in. So my advice is to ignore the blog article you mentioned in your question.

这样的代码不单单只出现无用或无价值但危险的,因为没有添加到您的代码,但依赖的好处!

Code like this is not just only useless or worthless but dangerous because there is no benefit added to your code but a dependency!

public interface IUnitOfWork:IDisposable
{
    int SaveChanges();
}

public interface IDALContext : IUnitOfWork
{
    ICategoryRepository Categories { get; }
    IProductRepository Products { get; }
}

要回答有一些抽象的域和数据映射之间调解你的问题层,像个内存中的域对象集是大项目的一绝。以及其引擎盖下的UnitOfWork机制能帮助获得了一些数据访问抽象解耦业务逻辑

To answer your question having some abstraction that mediates between the domain and data mapping layers, acting like an in-memory domain object collection is a must for "big" projects. And having a UnitOfWork mechanism under the hood can help decouple your business logic from access to a some data access abstraction.

TL; TR;
库和的UnitOfWork可以帮助你,但不喜欢在给定的博客文章运用它。

TL;TR; Repository and UnitOfWork can help you but don't apply it like in the given blog post.

这篇关于为工作单元和存储库模式,为大型项目非常有用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆