小编Mon*_*s X的帖子

使用WebAPI和RavenDB进行基本会话处理

用这个作为基础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; }

}
Run Code Online (Sandbox Code Playgroud)

ravendb asp.net-web-api

6
推荐指数
1
解决办法
1672
查看次数

标签 统计

asp.net-web-api ×1

ravendb ×1