使用 Raven DB 的数据访问架构

发布于 2024-11-05 14:10:49 字数 235 浏览 0 评论 0原文

我可以将哪些数据访问架构与 Raven DB 结合使用?

基本上,我想通过接口分离持久性,因此我不会将底层存储暴露给上层。即,我不希望我的域看到来自 Raven DB 的 IDocumentStoreIDocumentSession

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

你有什么想法?

What data access architectures are available that I can use with Raven 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?

What are your thoughts?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千秋岁 2024-11-12 14:10:49

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

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

  • 存储库模式(正如您所做的那样)
  • 使用 StructureMap Moq 进行依赖注入
  • 用于模拟测试 用于
  • 隔离业务逻辑的服务层(不确定这里的模式..或者即使这个 。

因此,当我希望从 RavenDB(持久性源)获取任何数据时,我将使用服务,然后它将调用适当的存储库,这样,我就不会将存储库暴露给应用程序 存储库非常重或复杂 -> 它基本上是一个 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(哇!)

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 :-

  • Repository Pattern (as you've done)
  • Dependency Injection with StructureMap
  • Moq for mock testing
  • Service layer for isolating business logic (not sure of the pattern here .. or even if this is a pattern.

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.

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();
    }
}

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.

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

夜未央樱花落 2024-11-12 14:10:49

你想通过这个达到什么目的?

您无法构建同时使用 RDBMS 和 DocDB 的应用程序,至少效率不高。您必须自己决定要使用哪个数据库,然后一直使用它。如果您决定使用 RDMBS,您可以使用 NHibernate,然后再说一次 - 不需要任何其他抽象层。

What are you trying to achieve by that?

You can't build an application which makes use of both an RDBMS and DocDB, not efficiently at least. You have to decide for yourself which database you are going to use, and then go all the way with it. If you decide to go with an RDMBS, you can use NHibernate for example, and then again - no need for any other abstraction layer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文