我可以将哪些数据访问架构与 Raven DB 一起使用?
基本上,我想通过接口分离持久性,所以我不会将下划线存储暴露给上层。即我不希望我的域看到来自 Raven DB 的IDocumentStore或IDocumentSession 。
我已经实现了通用存储库模式,这似乎有效。但是,我不确定这实际上是正确的方法。也许我应该进行命令查询隔离或其他什么?
你怎么认为?
我可以将哪些数据访问架构与 Raven DB 一起使用?
基本上,我想通过接口分离持久性,所以我不会将下划线存储暴露给上层。即我不希望我的域看到来自 Raven DB 的IDocumentStore或IDocumentSession 。
我已经实现了通用存储库模式,这似乎有效。但是,我不确定这实际上是正确的方法。也许我应该进行命令查询隔离或其他什么?
你怎么认为?
就个人而言,我对命令模式并没有真正的经验。我看到它被用于Rob Ashton 的优秀教程中。
对于我自己,我将尝试使用以下内容:-
因此,当我希望从 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 等......而且它是伪代码......但是您可以看到在存储库存在时服务是如何丰富的(假设是,对于我至少)简单或更轻。然后我只通过服务公开任何数据。
这就是我现在所做的.NET
,Entity Framework
而且我离尝试这个项目还有几个小时的时间RavenDb
(WOOT!)
你想达到什么目的?
您无法构建同时使用 RDBMS 和 DocDB 的应用程序,至少效率不高。您必须自己决定要使用哪个数据库,然后一直使用它。如果您决定使用 RDMBS,则可以使用 NHibernate,然后再使用 - 不需要任何其他抽象层。