Data access architectures with Raven DB

后端 未结 2 1538
逝去的感伤
逝去的感伤 2021-02-05 20:12

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

2条回答
  •  终归单人心
    2021-02-05 20:59

    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 userRepository, 
                           ILoggingService loggingService)
        {
            Repository = userRepository;
            LoggingService = loggingService;
        }
    
        public IEnumberable FindWithIsActive(int page, int count)
        {
            // Note: Repository.Find() returns an IQueryable 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!)

提交回复
热议问题