我正在使用Ninject for IoC。我有以下课程。
// 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;
}
}
目前我的ninject绑定如下所示,为接口分配具体类的新实例。
ninjectKernel.Bind<IUnitOfWork>().To<UnitOfWork>();
ninjectKernel.Bind<IProductRepository>().To<EFProductRepository>();
使用我的ninject控制器工厂,我需要将相同的IUnitOfWork类实例注入ProductController和EFProductRepository。请指导我。