Hi,
I'm trying to log ABP Audit Log info to AWS CloudWatch using ticket response - https://support.abp.io/QA/Questions/218
[Dependency(ReplaceServices = true)]
[ExposeServices(typeof(IAuditingStore))]
public class CustomAuditingStore : AuditingStore
{
    private readonly LogEventBatch _repo = new LogEventBatch();
    private readonly IAmazonCloudWatchLogs _client;
    private int _requestCount = 5;
    private static readonly Regex InvalidSequenceTokenRegex = new
    Regex(@"The given sequenceToken is invalid. The next expected sequenceToken is: (\d+)");
    public CustomAuditingStore(
    IAuditLogRepository auditLogRepository,
    IGuidGenerator guidGenerator,
    IUnitOfWorkManager unitOfWorkManager,
    IOptions<AbpAuditingOptions> options)
    : base(auditLogRepository, guidGenerator, unitOfWorkManager, options)
    {
        _client = CloudWatchLog.GetClient();
    }
The class CustomAuditStore seems to work just fine in my POC code but when I added it to my main Application project and when I run unit tests, it gives me below error -
Autofac.Core.DependencyResolutionException : An exception was thrown while activating Volo.Abp.EntityFrameworkCore.EntityHistory.EntityHistoryHelper -> ProfileManagement.CustomAuditingStore. ---- Autofac.Core.DependencyResolutionException : None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'ProfileManagement.CustomAuditingStore' can be invoked with the available services and parameters: Cannot resolve parameter 'Volo.Abp.AuditLogging.IAuditLogRepository auditLogRepository' of constructor 'Void .ctor(Volo.Abp.AuditLogging.IAuditLogRepository, Volo.Abp.Guids.IGuidGenerator, Volo.Abp.Uow.IUnitOfWorkManager, Microsoft.Extensions.Options.IOptions`1[Volo.Abp.Auditing.AbpAuditingOptions])'.
Could you please help and advise?
3 Answer(s)
- 
    0Hi, Can you provide steps and share some unit tests code? Thanks. 
- 
    0Hi, Please find below code snippet for one of unit test class. Let me know if need further information. public class SupplierRegistrationServiceTests : ProfileManagementApplicationTestBase { private readonly ISupplierRegistrationAppService _supplierRegistrationAppService; private readonly ISupplierRegistrationRepository _supplierRegistrationRepository; private readonly ISupplierRepository _supplierRepository; private readonly ISupplierCodeRepository _supplierCodeRepository; private readonly IBusinessEntityRepository _businessEntityRepository; private readonly ISupplierUserProfileRepository _supplierUserProfileRepository; public SupplierRegistrationServiceTests() { _supplierRegistrationAppService = GetRequiredService<ISupplierRegistrationAppService>(); _supplierRegistrationRepository = GetRequiredService<ISupplierRegistrationRepository>(); _supplierRepository = GetRequiredService<ISupplierRepository>(); _supplierCodeRepository = GetRequiredService<ISupplierCodeRepository>(); _businessEntityRepository = GetRequiredService<IBusinessEntityRepository>(); _supplierUserProfileRepository = GetRequiredService<ISupplierUserProfileRepository>(); } [Fact] public async Task RegisterAsync() { var supplierCodeList = new List<SupplierCodeCreateDto> { new SupplierCodeCreateDto { Code = "24865", IsPrimary = true, SupplierId = Guid.Parse("99255F1D-9A43-4523-A499-96839ABFD423") }, new SupplierCodeCreateDto { Code = "17596", IsPrimary = false, SupplierId = Guid.Parse("99255F1D-9A43-4523-A499-96839ABFD423") } }; var supplierCreateDto = new SupplierCreateDto { Name = "Microsoft", BusinessEntityId = Guid.Parse("231c8aac-3355-4c8b-84d7-eabb4ceba041"), SupplierCodes = supplierCodeList }; var supplierUserProfileCreateDto = new SupplierUserProfileCreateDto { FirstName = "Bill", LastName = "Gate", Email = "Bill.Gate@yahoo.com", Designation = "Executive", PhoneNumber = "99999999", IsAdmin = false, IsPrimary = true, CallingCountryCode = "91", PhoneType = PhoneType.Mobile }; var supplierRegistration = new SupplierRegistrationCreateDto { FinancingModelId = 1,//Need to change later TermsAndConditions = true, TermsAndConditionsTime = DateTime.Now.Date, Supplier = supplierCreateDto }; var input = new SupplierRegistrationProcessDto { SupplierRegistration = supplierRegistration, SupplierUserProfile = supplierUserProfileCreateDto }; // Act var serviceResult = await _supplierRegistrationAppService.RegisterAsync(input); // Assert var result = await _supplierRegistrationRepository.FindAsync(c => c.Id == serviceResult.Id); result.ShouldNotBe(null); // Assert var supplierResult = await _supplierRepository.FindAsync(c => c.Id == result.SupplierId); supplierResult.ShouldNotBe(null); supplierResult.Name.ShouldBe("Microsoft"); supplierResult.BusinessEntityId.ShouldBe(Guid.Parse("231c8aac-3355-4c8b-84d7-eabb4ceba041")); }Also, below is the error - SCV.Litmus.ProfileManagement.SupplierRegistrations.SupplierRegistrationServiceTests.RegisterAsyncSource: SupplierRegistrationApplicationTests.cs line 37 Duration: 1 ms Message: Autofac.Core.DependencyResolutionException : An exception was thrown while activating Volo.Abp.EntityFrameworkCore.EntityHistory.EntityHistoryHelper -> SCV.Litmus.ProfileManagement.CustomAuditingStore. ---- Autofac.Core.DependencyResolutionException : None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'SCV.Litmus.ProfileManagement.CustomAuditingStore' can be invoked with the available services and parameters: Cannot resolve parameter 'Volo.Abp.AuditLogging.IAuditLogRepository auditLogRepository' of constructor 'Void .ctor(Volo.Abp.AuditLogging.IAuditLogRepository, Volo.Abp.Guids.IGuidGenerator, Volo.Abp.Uow.IUnitOfWorkManager, Microsoft.Extensions.Options.IOptions 1[Volo.Abp.Auditing.AbpAuditingOptions])'. Stack Trace: InstanceLookup.Activate(IEnumerable1 parameters, Object& decoratorTarget) InstanceLookup.Execute() ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable1 parameters) InstanceLookup.ResolveComponent(IComponentRegistration registration, IEnumerable1 parameters) ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) AutowiringPropertyInjector.InjectProperties(IComponentContext context, Object instance, IPropertySelector propertySelector, IEnumerable1 parameters) <>c__DisplayClass34_0.<PropertiesAutowired>b__1(Object s, ActivatingEventArgs1 e) ComponentRegistration.RaiseActivating(IComponentContext context, IEnumerable1 parameters, Object& instance) InstanceLookup.Activate(IEnumerable1 parameters, Object& decoratorTarget) InstanceLookup.Execute() ResolveOperation.GetOrCreateInstance(ISharingLifetimeScope currentOperationScope, IComponentRegistration registration, IEnumerable1 parameters) ResolveOperation.ResolveComponent(IComponentRegistration registration, IEnumerable1 parameters) ResolveOperation.Execute(IComponentRegistration registration, IEnumerable1 parameters) LifetimeScope.ResolveComponent(IComponentRegistration registration, IEnumerable1 parameters) ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable1 parameters, Object& instance) ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable1 parameters) ResolutionExtensions.Resolve(IComponentContext context, Type serviceType, IEnumerable1 parameters) ResolutionExtensions.Resolve(IComponentContext context, Type serviceType) AutofacServiceProvider.GetRequiredService(Type serviceType) ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType) ServiceProviderServiceExtensions.GetRequiredService[T](IServiceProvider provider) UnitOfWorkDbContextProvider1.CreateDbContextWithTransaction(IUnitOfWork unitOfWork) UnitOfWorkDbContextProvider1.CreateDbContext(IUnitOfWork unitOfWork) UnitOfWorkDbContextProvider1.CreateDbContext(IUnitOfWork unitOfWork, String connectionStringName, String connectionString) <>c__DisplayClass3_0.<GetDbContext>b__0() <>c__DisplayClass6_02.<GetOrAdd>b__0(TKey k) AbpDictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary2 dictionary, TKey key, Func2 factory) AbpDictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary2 dictionary, TKey key, Func1 factory) UnitOfWork.GetOrAddDatabaseApi(String key, Func1 factory) UnitOfWorkDbContextProvider1.GetDbContext() EfCoreRepository2.get_DbContext() EfCoreRepository2.get_DbSet() EfCoreRepository2.InsertAsync(TEntity entity, Boolean autoSave, CancellationToken cancellationToken) AsyncInterceptorBase.ProceedAsynchronous[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo) CastleAbpMethodInvocationAdapterWithReturnValue1.ProceedAsync() UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) CastleAsyncAbpInterceptorAdapter1.InterceptAsync[TResult](IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) SupplierCodeDataSeedContributor.SeedAsync(DataSeedContext context) line 21 DataSeeder.SeedAsync(DataSeedContext context) AsyncInterceptorBase.ProceedAsynchronous(IInvocation invocation, IInvocationProceedInfo proceedInfo) CastleAbpMethodInvocationAdapter.ProceedAsync() UnitOfWorkInterceptor.InterceptAsync(IAbpMethodInvocation invocation) CastleAsyncAbpInterceptorAdapter1.InterceptAsync(IInvocation invocation, IInvocationProceedInfo proceedInfo, Func3 proceed) <<SeedTestData>b__0>d.MoveNext() line 35 --- End of stack trace from previous location where exception was thrown --- TaskExtensions.WaitAndUnwrapException(Task task) <>c__DisplayClass15_0.<Run>b__0(Task t) ContinuationTaskFromTask.InnerInvoke() <.cctor>b__274_0(Object obj) ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location where exception was thrown --- ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location where exception was thrown --- TaskExtensions.WaitAndUnwrapException(Task task) AsyncContext.Run(Func1 action) AsyncHelper.RunSync(Func1 action) ProfileManagementTestBaseModule.SeedTestData(ApplicationInitializationContext context) line 31 ProfileManagementTestBaseModule.OnApplicationInitialization(ApplicationInitializationContext context) line 26 OnApplicationInitializationModuleLifecycleContributor.Initialize(ApplicationInitializationContext context, IAbpModule module) ModuleManager.InitializeModules(ApplicationInitializationContext context) AbpApplicationBase.InitializeModules() AbpApplicationWithExternalServiceProvider.Initialize(IServiceProvider serviceProvider) AbpIntegratedTest1.ctor() ProfileManagementTestBase1.ctor() ProfileManagementApplicationTestBase.ctor() SupplierRegistrationServiceTests.ctor() line 25 ----- Inner Stack Trace ----- ReflectionActivator.GetValidConstructorBindings(IComponentContext context, IEnumerable1 parameters) ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable1 parameters) InstanceLookup.Activate(IEnumerable`1 parameters, Object& decoratorTarget)
- 
    0I can't reproduce your problem. Could your use CLI to create a free template to reproduce this problem? thanks. 
 
                                