我可以将哪些数据访问架构与 Raven DB 结合使用?
基本上,我想通过接口分离持久性,因此我不会将底层存储暴露给上层。 IE。我不想让别人看到我的域名文档存储库 or 文档会话它们来自 Raven DB。
我已经实现了通用存储库模式,这似乎有效。但是,我不确定这实际上是正确的方法。也许我应该采取命令查询隔离或其他方式?
你怎么看?
就我个人而言,我对命令模式并没有真正的经验。我看到它被用在Rob Ashton 的精彩教程 http://codeofrob.com/archive/2010/09/28/ravendb-image-gallery-project-i.aspx.
对于我自己来说,我将尝试使用以下方法:-
- 存储库模式(正如您所做的那样)
- 使用 StructureMap 进行依赖注入
- 模拟测试起订量
- 用于隔离业务逻辑的服务层(不确定这里的模式..或者即使这是一种模式。
因此,当我希望从 RavenDB(持久性源)获取任何数据时,我将使用服务,然后服务将调用适当的存储库。这样,我不会将存储库暴露给应用程序,存储库也不会非常重或复杂 -> 它基本上是 FindAll / Save / Delete。
eg.
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 等.....并且它是伪代码..但您可以看到服务是如何的rich而存储库是(应该是,至少对我来说)simple or lighter。然后我只通过服务公开任何数据。
这就是我现在所做的.NET
and Entity Framework
我实际上距离尝试这个还有几个小时RavenDb
(WOOT!)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)