I'm trying to register a custom model binder
in asp.net(core 3.0)
startup.cs
based on the following examples:
The code below is not working in asp.net core 3.0
, can someone please help - thanks!
services.AddMvc()
.AddMvcOptions(options =>
{
IHttpRequestStreamReaderFactory readerFactory = services.BuildServiceProvider().GetRequiredService<IHttpRequestStreamReaderFactory>();
options.ModelBinderProviders.Insert(0, new NtBodyModelBinderProvider(options.InputFormatters, readerFactory));
});
I'M GETTING THE FOLLOWING ERROR WHEN I TRY TO RUN THE APPLICATION.
System.AggregateException
HResult=0x80131500
Message=Some services are not able to be constructed (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Mvc.ModelBinding.IModelBinderProvider Lifetime: Scoped ImplementationType: CustomerCash.External.Api.ModelBinders.NtBodyModelBinderProvider': Unable to resolve service for type 'System.Collections.Generic.IList1[Microsoft.AspNetCore.Mvc.Formatters.IInputFormatter]' while attempting to activate 'CustomerCash.External.Api.ModelBinders.NtBodyModelBinderProvider'.) (Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Mvc.ModelBinding.IModelBinder Lifetime: Scoped ImplementationType: CustomerCash.External.Api.ModelBinders.NtBodyModelBinder': Unable to resolve service for type 'System.Collections.Generic.IList
1[Microsoft.AspNetCore.Mvc.Formatters.IInputFormatter]' while attempting to activate 'CustomerCash.External.Api.ModelBinders.NtBodyModelBinder'.)
Source=Microsoft.Extensions.DependencyInjection
StackTrace:
at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor(IEnumerable1 serviceDescriptors, ServiceProviderOptions options)
at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider(IServiceCollection services, ServiceProviderOptions options)
at Microsoft.Extensions.DependencyInjection.DefaultServiceProviderFactory.CreateServiceProvider(IServiceCollection containerBuilder)
at Microsoft.Extensions.Hosting.Internal.ServiceFactoryAdapter
1.CreateServiceProvider(Object containerBuilder)
at Microsoft.Extensions.Hosting.HostBuilder.CreateServiceProvider()
at Microsoft.Extensions.Hosting.HostBuilder.Build()
at CustomerCash.External.Api.Program.Main(String[] args) in C:\Development\JamesHay\jhcode\CustomerCashExternal\src\CustomerCash.External.Api\Program.cs:line 11
This exception was originally thrown at this call stack: [External Code]
Inner Exception 1: InvalidOperationException: Error while validating the service descriptor 'ServiceType: Microsoft.AspNetCore.Mvc.ModelBinding.IModelBinderProvider Lifetime: Scoped ImplementationType: CustomerCash.External.Api.ModelBinders.NtBodyModelBinderProvider': Unable to resolve service for type 'System.Collections.Generic.IList`1[Microsoft.AspNetCore.Mvc.Formatters.IInputFormatter]' while attempting to activate 'CustomerCash.External.Api.ModelBinders.NtBodyModelBinderProvider'.
Inner Exception 2: InvalidOperationException: Unable to resolve service for type 'System.Collections.Generic.IList`1[Microsoft.AspNetCore.Mvc.Formatters.IInputFormatter]' while attempting to activate 'CustomerCash.External.Api.ModelBinders.NtBodyModelBinderProvider'.
User contributions licensed under CC BY-SA 3.0