gpt4 book ai didi

c# - Raven DB 的数据访问架构

转载 作者:可可西里 更新时间:2023-11-01 08:26:34 25 4
gpt4 key购买 nike

Raven DB 可以使用哪些数据访问架构?

基本上,我想通过接口(interface)分离持久性,所以我不会将下划线存储暴露给上层。 IE。我不希望我的域看到来自 Raven DB 的 IDocumentStoreIDocumentSession

我已经实现了通用存储库模式,这似乎行之有效。但是,我不确定这实际上是正确的方法。也许我应该转向命令查询隔离或其他东西?

你有什么想法?

最佳答案

就个人而言,我对命令模式并没有真正的经验。我看到它被用于Rob Ashton's excellent tutorial .

对于我自己,我将尝试使用以下内容:-

  • 存储库模式(如您所做)
  • 使用 StructureMap 进行依赖注入(inject)
  • 模拟测试起订量
  • 用于隔离业务逻辑的服务层(不确定这里的模式......或者即使这是一种模式。

因此,当我希望从 RavenDB(持久性源)获取任何数据时,我将使用 Services,然后它将调用适当的存储库。这样,我就不会将存储库暴露给应用程序,存储库也不会非常繁重或复杂 -> 它基本上是一个 FindAll/Save/Delete。

例如。

public SomeController(IUserService userService, ILoggingService loggingService)
{
UserService = userService;
LoggingService = loggingService;
}

public ActionMethod Index()
{
// Find all active users, page 1 and 15 records.
var users = UserService.FindWithIsActive(1, 15);
return View(new IndexViewModel(users));
}

public class UserService : IUserService
{
public UserService(IGenericReposistory<User> userRepository,
ILoggingService loggingService)
{
Repository = userRepository;
LoggingService = loggingService;
}

public IEnumberable<User> FindWithIsActive(int page, int count)
{
// Note: Repository.Find() returns an IQueryable<User> in this case.
// Think of it as a SELECT * FROM User table, if it was an RDMBS.
return Repository.Find()
.WithIsActive()
.Skip(page)
.Take(count)
.ToList();
}
}

所以这是一个非常简单和人为的例子,没有错误/验证检查、try/catch 等......而且它是伪代码..但你可以看到服务是多么丰富而存储库(至少对我来说应该是)简单更轻。然后我只通过服务公开任何数据。

这就是我现在使用 .NETEntity Framework 所做的,而且我还需要几个小时才能使用 RavenDb (哇!)

关于c# - Raven DB 的数据访问架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5909400/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com