Ayende @ Rahien

Hi!
My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:

ayende@ayende.com

+972 52-548-6969

, @ Q c

Posts: 6,125 | Comments: 45,488

filter by tags archive

RavenDB session management in ASP.Net Web API

time to read 1 min | 122 words

This was brought up in the mailing list, and I thought it was an interesting solution, therefor, this post.

image

A couple of things to note here. I would actually rather use the Initialize() / Dispose() methods for this, but the problem is that we don’t really have a way at the Dispose() to know if the action threw an exception. Hence, the need to capture the ExecuteAsync() operation.

For fun, you can also use the async session as well, which will integrate very nicely into the async nature of most of the Web API.


Comments

Tugberk

Just curious, I am fairly new to RavenDb and so far, I have seen that mocking is not the way we test along with RavenDb.

But in above case, don't we direct dependency on DocumentStore? For an ASP.NET Web API application which has unit testing in mind, what would you recommend?

Ayende Rahien

Tugberk, RavenDB can run in pure in memory mode, perfect for unit testing.

ashic

Had a similar question in mind - do you recommend firing up an in memory raven db per unit test or fire one up and use for a batch of tests. Is there any performance issue in firing up an in memory store (since using a fresh one per test would be purer).

Ayende Rahien

Ashic, We use one in memory store per test.

Ryan Riley

Why not create a DelegatingHandler and push that into your configuration? You can push the session object into HttpRequestMessage.Items. Was there a reason you chose to subclass ApiController instead?

Ayende Rahien

Ryan, It was the most obvious thing to do, this is similar to how I handle things in ASP.Net MVC

Comment preview

Comments have been closed on this topic.

FUTURE POSTS

  1. The design of RavenDB 4.0: Physically segregating collections - 2 hours from now
  2. RavenDB 3.5 Whirlwind tour: I need to be free to explore my data - about one day from now
  3. RavenDB 3.5 whirl wind tour: I'll have the 3+1 goodies to go, please - 4 days from now
  4. The design of RavenDB 4.0: Voron has a one track mind - 5 days from now
  5. RavenDB 3.5 whirl wind tour: Digging deep into the internals - 6 days from now

And 12 more posts are pending...

There are posts all the way to May 30, 2016

RECENT SERIES

  1. The design of RavenDB 4.0 (14):
    03 May 2016 - Making Lucene reliable
  2. RavenDB 3.5 whirl wind tour (14):
    04 May 2016 - I’ll find who is taking my I/O bandwidth and they SHALL pay
  3. Tasks for the new comer (2):
    15 Apr 2016 - Quartz.NET with RavenDB
  4. Code through the looking glass (5):
    18 Mar 2016 - And a linear search to rule them
  5. Find the bug (8):
    29 Feb 2016 - When you can't rely on your own identity
View all series

Syndication

Main feed Feed Stats
Comments feed   Comments Feed Stats