2

I am using Ninject for IoC. I have the following classes.

// Repository
public class EFProductRepository : IProductRepository, IUnitOfWorkRepository
{
  private IUnitOfWork unitOfWork;
  private EFDbContext efDbContext;

  public EFProductRepository(IUnitOfWork uow)
  {
    unitOfWork = uow;
    efDbContext = new EFDbContext();
  }
  //
}

// Controller
public class ProductController : Controller
{
  private IUnitOfWork unitOfWork;
  private IProductRepository productRepository;

  public ProductController(IUnitOfWork uow, IProductRepository repo)
  {
    unitOfWork = uow;
    productRepository = repo;
  }
}

Currently my ninject bindings are as follow which assign new instance of the concrete class for the interface.

ninjectKernel.Bind<IUnitOfWork>().To<UnitOfWork>();
ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>();

using my ninject controller factory, I need to inject same instance of the IUnitOfWork class to the ProductController and EFProductRepository. Please guide me.

Muneer
  • 7,384
  • 7
  • 38
  • 62
  • 6
    Use `InRequestScope` method. Example can be found at http://stackoverflow.com/questions/3897690/asp-net-mvc-ninject-single-instance-per-request-for-multiple-constructors. – Patko Jul 31 '13 at 19:30

0 Answers0