title: Looking for a Ninject scope that behaves like InRequestScope
body: <p>On my service layer I have injected an <code>UnitOfWork</code> and 2 repositories in the constructor. The Unit of Work and repository have an instance of a <code>DbContext</code> I want to share between the two of them. How can I do that with Ninject ? Which scope should be considered ?</p>
  
  <p>I am <strong>not in a web application</strong> so I can't use <code>InRequestScope</code>.</p>
  
  <p>I try to do something similar... and I am using DI however, I need my UoW to be <code>Dispose</code>d and created like this.</p>
  
  <pre><code>using (IUnitOfWork uow = new UnitOfWorkFactory.Create())
  {
      _testARepository.Insert(a);
      _testBRepository.Insert(b);
  
      uow.SaveChanges();
  }
  </code></pre>
  
  <p>EDIT: I just want to be sure i understand… after look at <a href="https://github.com/ninject/ninject.extensions.namedscope/wiki/InNamedScope" rel="noreferrer">https://github.com/ninject/ninject.extensions.namedscope/wiki/InNamedScope</a> i though about my current console application architecture which actually use Ninject.</p>
  
  <p>Lets say :</p>
  
  <p>Class A is a Service layer class</p>
  
  <p>Class B is an unit of work which take into parameter an interface (IContextFactory) </p>
  
  <p>Class C is a repository which take into parameter an interface    (IContextFactory)</p>
  
  <p>The idea here is to be able to do context operations on 2 or more repository and using the unit of work to apply the changes.</p>
  
  <p>Class D is a context factory (Entity Framework) which provide an instance (keep in a container) of the context which is shared between Class B et C (.. and would be for other repositories aswell).</p>
  
  <p>The context factory keep the instance in his container so i don’t want to reuse this instance all the name since the context need to be disposed at the end of the service operaiton.. it is the main purpose of the InNamedScope actually ? </p>
  
  <p>The solution would be but i am not sure at all i am doing it right, the services instance gonna be transcient which mean they actually never disposed ? :</p>
  
  <pre><code>Bind&lt;IScsContextFactory&gt;()
      .To&lt;ScsContextFactory&gt;()
      .InNamedScope("ServiceScope")
      .WithConstructorArgument(
           "connectionString", 
           ConfigurationUtility.GetConnectionString());
  
  Bind&lt;IUnitOfWork&gt;().To&lt;ScsUnitOfWork&gt;();
  
  Bind&lt;IAccountRepository&gt;().To&lt;AccountRepository&gt;();
  Bind&lt;IBlockedIpRepository&gt;().To&lt;BlockedIpRepository&gt;();
  
  Bind&lt;IAccountService&gt;().To&lt;AccountService&gt;().DefinesNamedScope("ServiceScope");
  Bind&lt;IBlockedIpService&gt;().To&lt;BlockedIpService&gt;().DefinesNamedScope("ServiceScope");
  </code></pre>