如何使用SimpleInjector、Repository和Context–CodeFirst业务逻辑层(我也想使用PerWebRequest方法)。在DAL层中,我有:publicinterfaceIRepositorywhereT:class{voidAdd(Tentity);voidDelete(T实体);无效删除(intid);无效更新(T实体);TGetById(intId);IQueryableAll();IEnumerable查找(Func谓词);}和:publicclassEFRepository:IRepository,IDisposablewhereT:class{#regionMembersprotectedDbContextContext{get;放;}protectedDbSetDbSet{get;放;}#endregion#区域构造函数publicEFRepository(DbContextdbContext){if(dbContext==null)thrownewArgumentNullException("dbContext");上下文=数据库上下文;DbSet=Context.Set();}和我的上下文:publicclassPASContext:DbContext,IDbContext{publicDbSetProducts{get;放;}公共DbSet用户{得到;放;}publicPASContext():base("PostAndSell"){}}如您所见,EFRepository只有一个带有一个参数的构造函数-这是因为我想使用SimpleInjector创建上下文实例并将其传递给创建时的存储库。在BLL中,我有一个ProductBLL类,我想从数据库中获取该类中的所有产品(使用某种GetAll方法)并传递给它,比方说HomeController。我真的需要有人跟我说话。我首先从nuger安装了正确的包(SimpleInjector和SimpleInjectorASP.NETIntegration)也在我的global.asax.cs文件中,在我添加的Application_Start()函数下:varcontainer=newSimpleInjector.Container();container.RegisterPerWebRequest
