LLBLGen 和存储库模式
我想知道在顶部 LLBLGen(适配器)上构建存储库是否是一个好主意。我不想再次过度设计和重新发明轮子。 DataAccessAdapter 类可以是某种通用存储库。它具有您需要的所有 CRUD 方法。
但另一方面,对于较大的项目,在 ORM 和服务层之间设置一个层可能会更好。
我想听听您的意见,如果您使用 LLBLGen 的存储库模式,如果是,为什么,如果不是,为什么不。
如果您有一些实施,请发布。
I was wondering if building a repository on the top LLBLGen (adapter) is a good idea. I don't want to overengineer and reinvent the wheel again. The DataAccessAdapter class could be some kind of a generic repository.It has all the CRUD methods you need.
But on the other side for a larger project it could be good to have a layer between your ORM and service layer.
I'd like to hear your opinions, if your using the repository pattern with LLBLGen,if yes why if no why not.
If you have some implementation, post it please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
直接的好处是防止锁定特定技术,让您以后可以灵活地选择合适的技术。
恕我直言,更重要的原因是强制执行通用语言。随着应用程序/系统的发展,您将需要以多种方式查询数据。存储库可以帮助您封装复杂的查询。
使用通用实现,您的消费者代码可能如下所示:
使用存储库,它可能如下所示:
第二个示例明确说明了查询的意图,使其更容易/更快地在未来。
然而(只是让事情变得复杂),您可以使用查询规范来隔离复杂的查询逻辑,然后与通用存储库一起使用来完成工作。请参阅这篇文章了解它是如何完成的。
我通常会执行以下操作:
最后一点:我曾经设计过一个可以在在线和离线模式下工作的应用程序。最简单的解决方案是实现两个具体的存储库(使用通用接口),并在客户端连接/断开连接时在它们之间切换(切换持久性技术的另一个示例)。
The immediate benefit is preventing lock-in to a particular technology, giving you the flexibility to choose the appropriate technology later on.
IMHO, a more important reason is to enforce the Ubiquitous Language. As your application/system evolves, you'll need to query data in multiple ways. The Repository can help you encapsulate complex queries.
With a generic implementation, your consumer code might look like this:
Using a repository, it would look like this:
The second example explictly states the intent of the query, making it easier/quicker to identify in the future.
However (just to complicate matters), you could use Query Specifications to isolate complex query logic, and use then with a generic Repository to get the job done. See this post to see how it's done.
I usually do the following:
A final note: I once designed an app that worked in both on-line and off-line mode. The easiest solution was to implement two concrete Repositories (using a common interface), and switch between them when the client was connected/disconnected (another example of switching the persistence technology).
我们将存储库与 LLBLGen 一起使用,但具有自助服务。我们正在使用存储库模式来简化我们的单元测试。对于简单的插入/更新,存储库只需调用传入实体的 save 方法。我们的最终目标是在存储库和业务逻辑之间来回传递域对象(不是 LLBLGEN 实体),并且在实现的存储库中仅具有 ORM(LLBLEN、LINQ-To-SQL 等)依赖项。
We are using the repository with LLBLGen, but with self-servicing. We are using the repository pattern for easing our unit tests. For simple insert/updates, the repository is simply calling the save method of the passed in entity. What we are eventually aiming for is passing domain objects (NOT LLBLGEN entities) back and forth between the repository and the business logic, and only have the ORM (LLBLEN, LINQ-To-SQL, etc) dependencies in the implemented repository.