Repository模式VS DAL [英] Repository Pattern vs DAL
问题描述
他们是同样的事情?刚刚结束的观看罗布·康纳利的店面教程和他们似乎是类似techinques。我的意思是,当我实现DAL对象,我有GetStuff,添加/删除等方法,我总是先写的接口,这样我以后可以切换分贝。
Are they the same thing? Just finished to watch Rob Connery's Storefront tutorial and they seem to be similar techinques. I mean, when I implement a DAL object I have the GetStuff, Add/Delete etc methods and I always write the interface first so that I can switch db later.
我是不是混淆的东西呢?
Am I confusing things?
推荐答案
你绝对不是谁混淆的事情之一。 : - )
You're definitely not the one who confuses things. :-)
我认为这个问题的答案取决于你想怎么一个纯粹的不满意。
I think the answer to the question depends on how much of a purist you want to be.
如果你想要的角度严格DDD点,这将带你下来一条路径。如果你看一下库作为帮助我们规范的服务和数据库之间分隔层的界面模式,将带你下来另一回事。
If you want a strict DDD point of view, that will take you down one path. If you look at the repository as a pattern that has helped us standardize the interface of the layer that separates between the services and the database it will take you down another.
从我的角度来看这个仓库只是明确规定进入data.Or换句话说层实现数据访问层的标准方法。有不同的版本库的实现之间存在一些差异,但概念是相同的。
The repository from my perspective is just a clearly specified layer of access to data.Or in other words a standardized way to implement your Data Access Layer. There are some differences between different repository implementations, but the concept is the same.
有些人会换上库的更多DDD约束而其他人将使用这个资源库作为数据库和业务层之间的调停方便。像DAL版本库隔离数据访问细节的服务层。
Some people will put more DDD constraints on the repository while others will use the repository as a convenient mediator between the database and the service layer. A repository like a DAL isolates the service layer from data access specifics.
这似乎使他们不同的一个实现的问题,是一个仓库通常与乘坐规范的方法创建的。该库将返回满足该规范的数据。我所见过的最传统的达尔斯,将有较大的一套方法,其中该方法将采取任何数量的参数。虽然这听起来像一个小的差异,这是一个大问题,当你进入LINQ和防爆pressions的领域。
我们的默认存储库界面看起来是这样的:
One implementation issue that seems to make them different, is that a repository is often created with methods that take a specification. The repository will return data that satisfies that specification. Most traditional DALs that I have seen, will have a larger set of methods where the method will take any number of parameters. While this may sound like a small difference, it is a big issue when you enter the realms of Linq and Expressions. Our default repository interface looks like this:
public interface IRepository : IDisposable
{
T[] GetAll<T>();
T[] GetAll<T>(Expression<Func<T, bool>> filter);
T GetSingle<T>(Expression<Func<T, bool>> filter);
T GetSingle<T>(Expression<Func<T, bool>> filter, List<Expression<Func<T, object>>> subSelectors);
void Delete<T>(T entity);
void Add<T>(T entity);
int SaveChanges();
DbTransaction BeginTransaction();
}
这是一个DAL或储存库?在这种情况下,我想它的两个。
Is this a DAL or a repository? In this case I guess its both.
金
这篇关于Repository模式VS DAL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!