ole*_*sii 12 c# architecture data-access-layer ravendb
我可以使用哪些数据访问体系结构与Raven DB一起使用?
基本上,我想通过接口分离持久性,所以我不会将下划线存储暴露给上层.即我不希望我的域看到来自Raven DB的IDocumentStore或IDocumentSession.
我已经实现了通用存储库模式,这似乎有效.但是,我不确定这是否是正确的方法.也许我会去命令查询隔离或其他什么?
你的想法是什么?
就个人而言,我对命令模式并不熟悉.我看到它被用在Rob Ashton的优秀教程中.
对于我自己,我将尝试使用以下内容: -
因此,当我希望从RavenDB(持久性源)获取任何数据时,我将使用Services,然后将调用相应的存储库.这样,我不会将存储库暴露给应用程序,也不会使存储库非常繁重或复杂 - >它基本上是一个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();
}
}
Run Code Online (Sandbox Code Playgroud)
所以这是一个非常简单和人为的例子,没有错误/验证检查,尝试/捕获等......而且它是伪代码..但你可以看到服务器是如何丰富而存储库是(假设是,为我至少)简单或轻松.然后我只通过服务公开任何数据.
这就是我现在所做的事情.NET
,Entity Framework
并且我真的需要几个小时才能完成RavenDb
(WOOT!)
归档时间: |
|
查看次数: |
1813 次 |
最近记录: |