无法解析参数“Volo.Abp.Domain.Repositories.IRepository”
Cannot resolve parameter 'Volo.Abp.Domain.Repositories.IRepository`
在 ABP Framework v5.1.3 中,我正在尝试使用通用 IRepository<> 为数据库播种数据(我知道这不是最佳做法)。
但是我无法让依赖注入工作。
我创建了一个示例项目来重现我在 GitHub 的问题。
private DbSet<Sample> Samples { get; set; }
几个星期前我在关注 Web Application Development Tutorial 时没有遇到这个问题。
这是我看到的错误的一部分:
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 ---
为什么在我的情况下它无法解析参数,但按照上面的教程进行操作时却可以正常工作?
制作 DbSet
public:
// private DbSet<Sample> Samples { get; set; }
public DbSet<Sample> Samples { get; set; }
在 ABP Framework v5.1.3 中,我正在尝试使用通用 IRepository<> 为数据库播种数据(我知道这不是最佳做法)。 但是我无法让依赖注入工作。
我创建了一个示例项目来重现我在 GitHub 的问题。
private DbSet<Sample> Samples { get; set; }
几个星期前我在关注 Web Application Development Tutorial 时没有遇到这个问题。
这是我看到的错误的一部分:
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 ---
为什么在我的情况下它无法解析参数,但按照上面的教程进行操作时却可以正常工作?
制作 DbSet
public:
// private DbSet<Sample> Samples { get; set; }
public DbSet<Sample> Samples { get; set; }