upgrade 2.0.2 --> 2.2.1 my custom repository can not be injected
See original GitHub issuemy repository code:
public abstract class EsdServiceRepositoryBase<TEntity, TPrimaryKey> : EfCoreRepositoryBase<EsdServiceDbContext, TEntity, TPrimaryKey>
where TEntity: class, IEntity<TPrimaryKey>
{
protected EsdServiceRepositoryBase(IDbContextProvider<EsdServiceDbContext> dbContextProvider)
: base(dbContextProvider) { }
}
public class EsdServiceRepository<TEntity, TPrimaryKey>
: EsdServiceRepositoryBase<TEntity, TPrimaryKey>
where TEntity : class, IEntity<TPrimaryKey>
{
public EsdServiceRepository(IDbContextProvider<EsdServiceDbContext> db) : base(db) { }
}
public class EsdServiceRepository<TEntity>
: EsdServiceRepositoryBase<TEntity, string>
where TEntity : class, IEntity<string>
{
public EsdServiceRepository(IDbContextProvider<EsdServiceDbContext> db) : base(db) { }
}
my application service code:
public class ApplyService : EsdServiceAppServiceBase, IApplyService
{
private readonly IRepository<Apply, string> _applyRepository;
public ApplyService(IRepository<Apply, string> applyRepository)
{
_applyRepository = applyRepository;
}
public async Task<GetApplyOutput> Get(string id)
{
var apply = await _applyRepository.GetAsync(id);
return apply.MapTo<GetApplyOutput>();
}
}
my EsdServiceDbContext code:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
GetModelTypes().ToList().ForEach(
(type) =>
{
modelBuilder.Entity(type);
});
base.OnModelCreating(modelBuilder);
}
private IEnumerable<Type> GetModelTypes()
{
Assembly assembly = typeof(EsdServiceCoreModule).GetTypeInfo().Assembly;
return assembly.GetTypes().Where(IsModelType);
}
public static bool IsModelType(Type type)
{
Type baseType = typeof(IEntity<>);
return Array.Exists(
type.GetInterfaces(),
t =>
t.GetTypeInfo().IsGenericType &&
t.GetTypeInfo().GetGenericTypeDefinition() == baseType
) &&
!type.GetTypeInfo().IsAbstract &&
!type.GetTypeInfo().IsGenericType &&
type.GetTypeInfo().IsClass &&
type.GetTypeInfo().IsPublic;
}
I did not use the IDbSet <> attribute in DbContext , and I tried to use “[AutoRepositoryTypes( typeof(IRepository<>), typeof(IRepository<,>), typeof(EsdServiceRepository<>), typeof(EsdServiceRepository<,>))]” on DbContext is also invalid
I use a single database, so I do not want to use IDbSet <>, please give a solution, thanks!
Exception Message:
Can’t create component ‘Zac.EsdService.OrderInfos.ApplyService’ as it has dependencies to be satisfied.\r\n\r\n’Zac.EsdService.OrderInfos.ApplyService’ is waiting for the following dependencies:\r\n- Service ‘Abp.Domain.Repositories.IRepository`2[[Zac.EsdService.OrderInfos.Apply, Zac.EsdService.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.String, System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e]]’ which was not registered.\r\n"
Issue Analytics
- State:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top GitHub Comments
Define a custom DbContextEntityFinder,
replace the default one in Module PreInitialize,
@hikalkan
Yes, you understand that!