-
Notifications
You must be signed in to change notification settings - Fork 2
RavenDB Provider
A RavenDB-backed persistable session store for use with Nancy.
(This is a community project with no formal relationships with the awesome Nancy project or the outstanding RavenDB project.)
The RavenDB IDocumentStore
object must be initialized up front, and should be implemented as a singleton. The examples below register an instance of an IDocumentStore
, then utilize it to register the RavenDB session store.
namespace ExampleNancyApp
{
using Nancy;
using Nancy.Bootstrapper;
using Nancy.Session.Persistable;
using Nancy.Session.RavenDB;
using Nancy.TinyIoc;
using Raven.Client.Documents;
using System;
public class ApplicationBootstrapper : DefaultNancyBootstrapper
{
public static IDocumentStore DocStore = new Lazy<IDocumentStore>(() =>
{
var store = new DocumentStore();
// configure store
return store.Initialize();
}).Value;
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
base.ApplicationStartup(container, pipelines);
// Register the document store
container.Register(DocStore);
// Register the session store
PersistableSessions.Enable(pipelines,
new RavenDBSessionConfiguration(container.Resolve<IDocumentStore>()));
}
}
}
module ExampleNancyApp
open Nancy
open Nancy.Bootstrapper
open Nancy.Session.Persistable
open Nancy.Session.RavenDB
open Raven.Client.Documents
/// Set up a database connection
let docStore = lazy (() ->
let store = new DocumentStore()
// configure options
store.Initialize())
type ApplicationBootstrapper() =
inherit DefaultNancyBootstrapper()
override this.ApplicationStartup (container, pipelines) =
base.ApplicationStartup (container, pipelines)
// RavenDB connection
container.Register<IDocumentStore>(docStore.Force ())
|> ignore
// Sessions
PersistableSessions.Enable
(pipelines, RavenDBSessionConfiguration(container.Resolve<IDocumentStore>()))
Imports Nancy
Imports Nancy.Bootstrapper
Imports Nancy.Session.Persistable
Imports Nancy.Session.RavenDB
Imports Nancy.TinyIoc
Imports Raven.Client.Documents
Namespace ExampleNancyApp
Public Class ApplicationBootstrapper
Inherits DefaultNancyBootstrapper
Private Shared Function InitStore() As IDocumentStore
Dim store = New DocumentStore()
Return store.Initialize()
End Function
Public Shared DocStore As IDocumentStore = New Lazy(Of IDocumentStore)(InitStore).Value
Protected Overrides Sub ApplicationStartup(container As TinyIoCContainer, pipelines As IPipelines)
MyBase.ApplicationStartup(container, pipelines)
' Register the document store
container.Register(Of IDocumentStore)(DocStore)
' Register the session store
PersistableSessions.Enable(pipelines,
New RavenDBSessionConfiguration(container.Resolve(Of IDocumentStore)))
End Sub
End Class
End Namespace
As you may have noticed in the examples above, the configuration object takes the IDocumentStore
as its only parameter. (There is a zero-parameter constructor as well, but if you do not specify a document store before enabling sessions, the provider will throw an exception.) This is only required configuration option.
In addition to the options provided by Nancy.Session.Persistable, the following options are available (SDHP uses all the defaults):
-
Database (string - default:
IDocumentStore
-configured database)This is the RavenDB database that will be used for persistence.
-
Collection (string - default: "Sessions")
This is the document collection within the RavenDB database that will be used for persistence; by convention, this name should be a plural noun (ex. "Visitors" instead of "Visitor").