使用 Raven DB 的数据访问架构 [英] Data access architectures with Raven DB

查看:22
本文介绍了使用 Raven DB 的数据访问架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以将哪些数据访问架构用于 Raven DB?

What data access architectures are available that I can use with Raven DB?

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

Basically, I want to separate persistence via interfaces, so I don't expose underline storage to the upper layers. I.e. I don't want my domain to see IDocumentStore or IDocumentSession which are from Raven DB.

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

I have implemented the generic repository pattern and that seems to work. However, I am not sure that is actually the correct approach. Maybe I shall go towards command-query segregation or something else?

你有什么想法?

推荐答案

就我个人而言,我对命令模式并没有真正的经验.我看到它被用于 Rob Ashton 的优秀教程.

Personally, I'm not really experienced with the Command Pattern. I saw that it was used in Rob Ashton's excellent tutorial.

就我自己而言,我将尝试使用以下方法:-

For myself, I'm going to try using the following :-

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

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

So when i wish to get any data from RavenDB (the persistence source), i'll use Services, which will then call the appropriate repository. This way, i'm not exposing the repository to the Application nor is the repository very heavy or complex -> it's basically a 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 等......而且它是伪代码......但是你可以看到服务是如何丰富而存储库是(至少对我来说)简单轻量.然后我只通过服务公开任何数据.

So that's a very simple and contrived example with no error/validation checking, try/catch, etc... .. and it's pseudo code .. but you can see how the services are rich while the repository is (suppose to be, for me at least) simple or lighter. And then I only expose any data via services.

这就是我现在使用 .NETEntity Framework 所做的事情,而我实际上距离 RavenDb 的使用还有几个小时的时间(哇!)

That's what I do right now with .NET and Entity Framework and I'm literally hours away from giving this a go with RavenDb (WOOT!)

这篇关于使用 Raven DB 的数据访问架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆