Note that there are some explanatory texts on larger screens.

plurals
  1. POI can't get the callscope of my session to work
    text
    copied!<p>I'm having trouble scoping my IDocumentSession dependency with Ninject. </p> <p>Every time my bus executes a command, I want a new IDocumentSession. Commandhandlers that are created by the factory should have that same instance of IDocumentSession injected. I thought putting the bus in a CallScope would work, but I think the AsFactory breaks the CallScope? How would I get this done?</p> <pre><code>public class Bus : IBus { private readonly ICommandHandlerFactory _factory; private readonly IDocumentSession _session; public Bus(ICommandHandlerFactory factory, IDocumentSession session) { _factory = factory; _session = session; } public void ExecuteCommand&lt;T&gt;(T command) where T : class { var handler = _factory.Create&lt;T&gt;(); handler.Handle(command); _session.SaveChanges(); } } public class ActivateAccountCommandHandler : ICommandHandler&lt;ActivateAccountCommand&gt; { private readonly IDocumentSession _session; public ActivateAccountCommandHandler(IDocumentSession session) { _session = session; } public void Handle(ActivateAccountCommand command) { // Do something } } kernel.Bind&lt;IDocumentStore&gt;().ToMethod(ctx =&gt; DocumentStore.Get()).InSingletonScope(); kernel.Bind&lt;IDocumentSession&gt;().ToMethod(ctx =&gt; ctx.Kernel.Get&lt;IDocumentStore&gt;().OpenSession()); kernel.Bind&lt;ICommandHandlerFactory&gt;().AsFactory(); kernel.Bind&lt;IBus&gt;().To&lt;Bus&gt;().InCallScope(); </code></pre> <p>I also tried with context preservation but this makes no difference.</p> <pre><code>kernel.Bind&lt;IDocumentSession&gt;().ToMethod(ctx =&gt; ctx.ContextPreservingGet&lt;IDocumentStore&gt;().OpenSession()); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload