abp-framework

Cannot resolve parameter 'Volo.Abp.Domain.Repositories.IRepository`


In ABP Framework v5.1.3, I'm trying to seed database with data using a generic IRepository<> (I know this isn't best practice). However I can't get the dependency injection to work.

I've created a sample project reproducing my issue at GitHub.

private DbSet<Sample> Samples { get; set; }

I didn't have this issue a couple weeks ago when following the Web Application Development Tutorial.

This is part of the error I'm seeing:

Unhandled exception. Autofac.Core.DependencyResolutionException: An exception was thrown while activating SampleProject.SampleProjectDataSeederContributor.
 ---> Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'SampleProject.SampleProjectDataSeederContributor' can be invoked with the av
ailable services and parameters:
Cannot resolve parameter 'Volo.Abp.Domain.Repositories.IRepository`2[SampleProject.Samples.Sample,System.Guid] sampleRepository' of constructor 'Void .ctor(Volo.Abp.Domain.Repositories.IRepository`2[SampleProject.Samples.Sample,Syste
m.Guid], Volo.Abp.Guids.IGuidGenerator)'.
   at Autofac.Core.Activators.Reflection.ReflectionActivator.GetAllBindings(ConstructorBinder[] availableConstructors, IComponentContext context, IEnumerable`1 parameters)
   at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters)
   at Autofac.Core.Activators.Reflection.ReflectionActivator.<ConfigurePipeline>b__11_0(ResolveRequestContext ctxt, Action`1 next)
   at Autofac.Core.Resolving.Middleware.DelegateMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext ctxt)
   at Autofac.Core.Resolving.Middleware.DisposalTrackingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext ctxt)
   at Autofac.Builder.RegistrationBuilder`3.<>c__DisplayClass41_0.<PropertiesAutowired>b__0(ResolveRequestContext ctxt, Action`1 next)
   at Autofac.Core.Resolving.Middleware.DelegateMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   at Autofac.Core.Resolving.Pipeline.ResolvePipelineBuilder.<>c__DisplayClass14_0.<BuildPipeline>b__1(ResolveRequestContext ctxt)
   at Autofac.Core.Resolving.Middleware.ActivatorErrorHandlingMiddleware.Execute(ResolveRequestContext context, Action`1 next)
   --- End of inner exception stack trace ---

Why is it that it cannot resolve the parameters in my case, but when following the tutorial above it's working?


Solution

  • Make the DbSet public:

    // private DbSet<Sample> Samples { get; set; }
    public DbSet<Sample> Samples { get; set; }