Created
March 5, 2012 19:19
-
-
Save brianwigfield/1980464 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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