【发布时间】:2014-01-03 03:11:00
【问题描述】:
我希望在我的 MVC 层中根本没有存储库。
我的 DAL 项目层中有通用的 EFRepository、IRepository 和 PASContext(继承自 DbContext)。
我已经在我的 MVC 项目下安装了具有快速启动功能的 Simple Injector,这使我可以在每个控制器的构造函数中获取我想要的存储库。
但在我的解决方案中,我也有 BLL 项目,我希望 MVC 层只与 BLL 层对话,因为这是项目架构,将来我想在 BLL 层内的类中添加逻辑。
我也不想在我的 BLL 层中创建上下文,但存储库没有构造函数,它接受 0 个参数,这是我的 ProductBLL 类:
public class BLLProducts
{
IRepository<Product> ProductRepository;
public BLLProducts(EFRepository<Product> Repository)
{
ProductRepository = Repository;
}
public ICollection<Product> getAll()
{
return ProductRepository.All().ToList();
}
}
如何在不创建存储库/上下文的情况下从控制器或 unitTest 启动 BLLProduct 类?所以我可以在这里保持我的抽象。
我知道我需要在这里以某种方式使用简单注射器,我只是不知道如何。
【问题讨论】:
标签: c# asp.net-mvc repository simple-injector business-layer