ABP实现的默认仓储已经足够大多场景的使用,个别场景还是需要创建自定义仓储。按照文档介绍方式实现过程中,出现了错误:
Target does not implement interface Abp.Domain.Repositories.IRepository`1[[Abp.Localization.ApplicationLanguage, Abp.Zero.Common, Version=4.8.1.0, Culture=neutral, PublicKeyToken=null]]
参数名: target
以下是修改后的代码:BatchInsertTestRepository<TEntity> 需要继承接口IRepository<TEntity>
- public class BatchInsertTestRepository<TEntity, TPrimaryKey> : BatchInsertTestRepositoryBase<TEntity, TPrimaryKey>
- where TEntity : class, IEntity<TPrimaryKey>
- {
- public BatchInsertTestRepository(IDbContextProvider<BatchInsertTestDbContext> dbContextProvider)
- : base(dbContextProvider)
- {
- }
- }
- public class BatchInsertTestRepository<TEntity> : BatchInsertTestRepository<TEntity, int>, <span style="color: #ff00ff;"><a href="https://www.codebye.com/tag/irepository" title="查看更多关于IRepository的文章" target="_blank">IRepository</a><TEntity></span> where TEntity : class, IEntity<int>
- {
- public BatchInsertTestRepository(IDbContextProvider<BatchInsertTestDbContext> dbContextProvider)
- : base(dbContextProvider)
- {
- }
- }
DbContext的部分实现:
- [AutoRepositoryTypes(
- typeof(<a href="https://www.codebye.com/tag/irepository" title="查看更多关于IRepository的文章" target="_blank">IRepository</a><>),
- typeof(<a href="https://www.codebye.com/tag/irepository" title="查看更多关于IRepository的文章" target="_blank">IRepository</a><,>),
- typeof(BatchInsertTestRepository<>),
- typeof(BatchInsertTestRepository<,>)
- )]
- public class BatchInsertTestDbContext : AbpZeroDbContext<Tenant, Role, User>
- { ... }