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());
IServiceProvider
you want to inject? Please show how it is used and what your intentions are. The answer to your question depends on those details. For instance, you you intend to resolve instances from it? Do you expect it to forward calls to the Simple InjectorContainer
? Why does your controller need a Service Locator?Container
.