Abp: where I can't get the IRepository?

Created on 7 Nov 2019  路  4Comments  路  Source: abpframework/abp

when my entity drive from AggregateRoot I can get the IRepository repository from constructor,but when my entity drive from Entity,it will raise am error below:
_Cannot resolve parameter 'Volo.Abp.Domain.Repositories.IRepository2[SyncData.Host.Domain.SyncTime,System.Guid] repository' of constructor 'Void .ctor(Volo.Abp.Domain.Repositories.IRepository2[SyncData.Host.Domain.SyncTime,System.Guid])'.
at Autofac.Core.Activators.Reflection.ReflectionActivator.GetValidConstructorBindings(IComponentContext context, IEnumerable1 parameters) at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable1 parameters)
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)_

This is my code:
public class SyncTimeService: CrudAppService CreateUpdateSyncTimeDto, CreateUpdateSyncTimeDto>, ISyncTimeService, IApplicationService
{
public SyncTimeService(IRepository repository)
: base(repository)
{

    }
}

Most helpful comment

when my entity drive from Entity,it will raise am error below

This is by design. See documentation: https://docs.abp.io/en/abp/latest/Entity-Framework-Core#add-default-repositories

If you want to create repositories for other entities too, then set includeAllEntities to true:

csharp services.AddAbpDbContext<MyDbContext>(options => { options.AddDefaultRepositories(includeAllEntities: true); });

All 4 comments

Please share your DbContext code.

Please share your DbContext code.

This is my dbcontext:

[ConnectionStringName("ChargeConn")]
    public class ChargeDbContext : AbpDbContext<ChargeDbContext>
    {
        public DbSet<Department> Department { get; set; }
        public DbSet<SyncTime> SyncTime { get; set; }
        public DbSet<SyncHis> SyncHis { get; set; }
        public DbSet<WriteBook> WriteBook { get; set; }
        public ChargeDbContext(DbContextOptions<ChargeDbContext> options) : base(options)
        {

        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.ConfigureCharge();
            base.OnModelCreating(modelBuilder);
        }
    }

And this is my EntityFrameworkCoreModule:

[DependsOn(
      typeof(SyncDataDomainModule),
        typeof(AbpEntityFrameworkCoreModule)
      )]
    public class ChargeEntityFrameworkCoreModule: AbpModule
    {
        public override void ConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.AddAbpDbContext<ChargeDbContext>(options =>
            {
                options.AddDefaultRepositories();
            }); 
        }
    }

when my entity drive from Entity,it will raise am error below

This is by design. See documentation: https://docs.abp.io/en/abp/latest/Entity-Framework-Core#add-default-repositories

If you want to create repositories for other entities too, then set includeAllEntities to true:

csharp services.AddAbpDbContext<MyDbContext>(options => { options.AddDefaultRepositories(includeAllEntities: true); });

when my entity drive from Entity,it will raise am error below

This is by design. See documentation: https://docs.abp.io/en/abp/latest/Entity-Framework-Core#add-default-repositories

If you want to create repositories for other entities too, then set includeAllEntities to true:

services.AddAbpDbContext<MyDbContext>(options =>
{
    options.AddDefaultRepositories(includeAllEntities: true);
});

Yes you are right,when I use the CLI, I fond is ok,so I compared the code the different is the includeAllEntities: true. Thank you very much.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ChangYinShung picture ChangYinShung  路  3Comments

derily picture derily  路  3Comments

hikalkan picture hikalkan  路  3Comments

wocar picture wocar  路  3Comments

hikalkan picture hikalkan  路  3Comments