Skip to content

Instantly share code, notes, and snippets.

@brianwigfield
Created March 5, 2012 19:19
Show Gist options
  • Save brianwigfield/1980464 to your computer and use it in GitHub Desktop.
Save brianwigfield/1980464 to your computer and use it in GitHub Desktop.
public class DocumentStoreRegistry : Registry
{
public DocumentStoreRegistry()
{
For<IDocumentStore>().Singleton()
.AddInstances(_ =>
_.ConstructedBy(ctor =>
{
var store = new DocumentStore { Url = ConfigurationManager.AppSettings["RAVENHQ_CONNECTION_STRING"] };
store.Initialize();
return store;
}));
For<IDocumentSession>().HttpContextScoped()
.AddInstances(_ => _.ConstructedBy(ctor => ctor.GetInstance<RavenDocumentSession>().GetSession()));
}
}
public class RavenDocumentSession : IDisposable
{
readonly IDocumentStore _store;
IDocumentSession _session;
public RavenDocumentSession(IDocumentStore store)
{
_store = store;
}
public IDocumentSession GetSession()
{
_session = _store.OpenSession();
return _session;
}
public void Dispose()
{
_session.SaveChanges();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment