Base solution for your next web application
Open Closed

using IConfigurationRoot in a background job: dependency ERROR #12315


User avatar
0
uenlkr4e created

Hi, I have this background job that inherits from AsyncBackgroundJob, ITransientDependency public class PrepareInvoiceEnvelopeJob : AsyncBackgroundJob<long>, ITransientDependency

And i have a private app configurator that i am trying to inject. private readonly IConfigurationRoot _appConfiguration;

But i get the following error:

Abp.BackgroundJobs.BackgroundJobManager - Castle.MicroKernel.Handlers.HandlerException: Can't create component 'uenlkr4e.Portal.PrepareInvoiceEnvelopeJob' as it has dependencies to be satisfied. 'uenlkr4e.Portal.PrepareInvoiceEnvelopeJob' is waiting for the following dependencies:

  • Service 'Microsoft.Extensions.Configuration.IConfigurationRoot' which was not registered.

What am i missing here? thanks in advance.

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

2 Answer(s)
  • User Avatar
    0
    oguzhanagir created
    Support Team

    Hi uenlkr4e

    You should use IConfiguration instead of IConfigurationRoot since the DI system provides IConfiguration by default. If you still want to use IConfigurationRoot, it is more appropriate to use it with IAppConfigurationAccessor. This interface has also been replaced in the module. You can refer to the sample code below.

    public class PrepareInvoiceEnvelopeJob : AsyncBackgroundJob<long>, ITransientDependency
    {
        private readonly IConfigurationRoot _appConfiguration;
    
        public PrepareInvoiceEnvelopeJob(IAppConfigurationAccessor appConfigurationAccessor)
        {
            _appConfiguration = appConfigurationAccessor.Configuration;
        }
    }
    
    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    uenlkr4e created

    Thank you, I will give it a try.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)