Cannot inject AuditLogAction IRepository
I need to retrieve an AuditLogAction record from AbpAuditLogActions table.
I created an AppService and injected the repo but throws me an error (did same with AuditLog and worked ok but not working with AuditLogAction)
public LogsAppServiceX(IRepository<AuditLogAction, Guid> repository) : base()
Error:
2020-03-29 15:18:55.942 -03:00 [ERR] ---------- RemoteServiceErrorInfo ---------- 2020-03-29 15:18:55.955 -03:00 [ERR] { "code": null, "message": "An internal error occurred during your request!", "details": null, "validationErrors": null } 2020-03-29 15:18:55.957 -03:00 [ERR] An exception was thrown while activating Castle.Proxies.LogsAppServiceXProxy. Autofac.Core.DependencyResolutionException: An exception was thrown while activating Castle.Proxies.LogsAppServiceXProxy. ---> Autofac.Core.DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'Castle.Proxies.LogsAppServiceXProxy' can be invoked with the available services and parameters: Cannot resolve parameter 'Volo.Abp.Domain.Repositories.IRepository
2[Volo.Abp.AuditLogging.AuditLogAction,System.Guid] repository' of constructor 'Void .ctor(Castle.DynamicProxy.IInterceptor[], Volo.Abp.Domain.Repositories.IRepository2[Volo.Abp.AuditLogging.AuditLogAction,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(IEnumerable1 parameters, Object& decoratorTarget) --- End of inner exception stack trace --- at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable1 parameters, Object& decoratorTarget) at Autofac.Core.Resolving.InstanceLookup.Execute() at Autofac.Core.Resolving.ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable1 parameters) at Autofac.Core.Resolving.ResolveOperation.Execute(IComponentRegistration registration, IEnumerable1 parameters) at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) at Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters) at Microsoft.AspNetCore.Mvc.Controllers.ServiceBasedControllerActivator.Create(ControllerContext actionContext) at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.g__CreateController|0(ControllerContext controllerContext) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync() --- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker. g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
The AuditLogAction entity does not have a repository by default. Please use IAuditLogRepository.
https://github.com/abpframework/abp/blob/33cb36ad5aa7867b6a93bb6a38ff48f17955cea5/modules/audit-logging/src/Volo.Abp.AuditLogging.Domain/Volo/Abp/AuditLogging/IAuditLogRepository.cs#L10
Please refer to: https://docs.abp.io/en/abp/latest/Entity-Framework-Core
Write this into the ConfigureServices method of your EF Core module:
context.Services.AddDefaultRepository(
typeof(AuditLogAction),
typeof(EfCoreRepository<AbpAuditLoggingDbContext, AuditLogAction, Guid>)
);
Then you can inject IRepository<AuditLogAction, Guid> when you need.