IServiceProvider that is not registered

When the application starts the error occurs

The constructor of type ImportExportController contains the parameter
with name ‘serviceProvider’ and type IServiceProvider that is not
registered. Please ensure IServiceProvider is registered, or change
the constructor of ImportExportController

My code

public class ImportExportController : BaseController
   private readonly IServiceProvider _serviceProvider;

   public ImportExportController(IServiceProvider serviceProvider)
     _serviceProvider = serviceProvider;

for the injection of dependencies I’m using the Simple Injector

The error happens in the container.Verify();

private static void Register(Container container)
   _container = container;
   container.Register<IXmlServices, XmlServices>();

I’m using _serviceProvider here
foreach (var element in productsToImport)
   using (var scope = _serviceProvider.CreateScope())
      var app = scope.ServiceProvider.GetService<IImportApp>();
      var task = Task.Run(() => app.ImportData(element, UserName, ImportID, PricesCurrencies));


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You need to register the IServiceProvider, in the same way you did for IXmlServices.

container.Register<IServiceProvider, ServiceProvider>();

Given that, the ServiceProvider is a class that implements interface IServiceProvider.

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x