I use NServiceBus (3.2.2), RavenDB (1.2.2017-Unstable) and Windsor (3.0.0.4001) in the MVC 4 project.
I have an IHandleMessages class that processes 3 different messages and needs an IDocumentSession and therefore defines a property such as:
public IDocumentSession DocumentSession { get; set; }
I copied the implementation of RavenDbUnitOfWork from NServiceBus
I registered IDocumentStore, IDocumentSession, and IManageUnitsOfWork in the Windsor container as follows:
container.Register(
Component
.For<IManageUnitsOfWork>()
.ImplementedBy<RavenUnitOfWork>()
.LifestyleTransient()
);
container.Register(
Component
.For<IDocumentStore>()
.UsingFactoryMethod(k => DocumentStoreHolder.DocumentStore)
.LifestyleSingleton(),
Component
.For<IDocumentSession>()
.UsingFactoryMethod(k => k.Resolve<IDocumentStore>().OpenSession())
.LifestyleTransient()
);
NServiceBus is configured to use my container:
Configure.With()
.CastleWindsorBuilder(container);
I ran into a problem that UnitOfWork and the message handler get different instances of DocumentSession. This means that objects stored in the session in the message handler are not saved, since SaveChanges () is called on another DocumentSession.
, concurrency/ RavenDb, () DocumentSession, .
Update:
, IDocumentSession Windsor, Scope, :
Component
.For<IDocumentSession>()
.UsingFactoryMethod(k => k.Resolve<IDocumentStore>().OpenSession())
.LifestyleScope()
, MVC, , , BeginScope().