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>();
container.Verify();
}
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));
listTask.Add(task);
}
}
Task.WaitAll(listTask.ToArray());
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
.