Aspnetboilerplate initialization of AppService and Repository giving error in .NET Core Worker Service

Viewed 457

We are using Aspnetboilerplate framework with .NET Core 3.1 and have already created Entity classes (EF Core manages database) and Application Services. This mechanism is working perfectly and we are able to retrieve and save data from our client applications.

We initiated a .NET Core Worker Service project in order to develop a background service. This service is required to connect with Aspnetboilerplate framework so that we are able to connect with database. However, no attempt is successful so far. Here are details what we tried:

Platform: .NET Core 3.1 Project type: .NET Core Worker Service Reference projects: Application and EntityFramework (2 projects referenced)

Main function in Program.cs

public static void Main(string[] args)
{
            using (var bootstrapper = AbpBootstrapper.Create<TxnParsingModule>())
            {
                bootstrapper.Initialize();                
            }

            CreateHostBuilder(args).Build().Run();
}

AbpModule Initialization has been performed:

[DependsOn(
        typeof(MViewCoreModule),
        typeof(MViewEntityFrameworkModule),
        typeof(MViewApplicationModule),
        typeof(AbpZeroCoreModule)
)]
public class TxnParsingModule : AbpModule
{
        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(typeof(TxnParsingModule).GetAssembly());
        }
}

After initialization of Host process for background worker class, we have TransactionJob class which actually requires AppService reference through Constructor injection as follows:

public class TransactionJob : IJob, ITransientDependency
    {
        //public IRepository<AtmInfo, long> atmRepository;
        //public TransactionJob(IRepository<AtmInfo, long> _atmRepository)
        //{
        //    this.atmRepository = _atmRepository;
        //}

        public IAtmInfoAppService atmService;
        public TransactionJob(IAtmInfoAppService _atmService)
        {
            this.atmService = _atmService;
        }

        public Task Execute(IJobExecutionContext context)
        {
            return Task.CompletedTask;
        }
    }

Above code gives following error on initialization:

Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.Extensions.Hosting.IHostedService Lifetime: Singleton ImplementationType: MView.TxnParsingService.Worker': Unable to resolve service for type 'Abp.Domain.Repositories.IRepository`2[MView.Core.Models.AtmInfo,System.Int64]' while attempting to activate 'MView.TxnParsingService.Worker'.)

Inner Exception 1:

InvalidOperationException: Error while validating the service descriptor 'ServiceType: Microsoft.Extensions.Hosting.IHostedService Lifetime: Singleton ImplementationType: MView.TxnParsingService.Worker': Unable to resolve service for type 'Abp.Domain.Repositories.IRepository`2[MView.Core.Models.AtmInfo,System.Int64]' while attempting to activate 'MView.TxnParsingService.Worker'.

Inner Exception 2:

InvalidOperationException: Unable to resolve service for type 'Abp.Domain.Repositories.IRepository`2[MView.Core.Models.AtmInfo,System.Int64]' while attempting to activate 'MView.TxnParsingService.Worker'.
0 Answers
Related