使用它作为基础 APIController,想法?主要是我对处理 dispose 中的 savechanges 与我在其他地方看到的 ExecuteAsync 方法感到好奇......
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
using System.Web.Http.Controllers;
using Raven.Client;
using Raven.Client.Document;
public abstract class RavenDbController : ApiController
{
private IDocumentStore _documentStore;
public IDocumentStore Store
{
get { return _documentStore ?? (_documentStore = LazyDocStore.Value); }
set { _documentStore = value; }
}
protected override void Initialize(HttpControllerContext controllerContext)
{
Session = Store.OpenSession();
base.Initialize(controllerContext);
}
protected override void Dispose(bool disposing)
{
using (Session)
{
Session.SaveChanges();
}
}
public IDocumentSession Session { get; set; }
}