与掠夺DB数据访问架构 [英] Data access architectures with Raven DB

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

问题描述

什么数据访问架构都可以,我可以与掠夺DB使用?

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

基本上,我想通过接口分开的持久性,所以不暴露下划线存储到上层。即我不希望我的域名看到的 IDocumentStore IDocumentSession 的这是由乌鸦DB。

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?

你有什么想法?

推荐答案

就个人而言,我真的不与命令模式的经验。我看到它在罗布阿什顿的优秀教程

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 /保存/删除

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语句,等等......,它是伪code ..但是你可以看到服务是如何的的当版本库(假设是,至少对我来说)的简单打火机的。然后,我只能通过服务公开任何数据。

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.

这就是我现在做与 .NET 实体框架,我从字面上小时的路程,从给这是一个用去 RavenDb (WOOT!)

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!)

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

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