I am trying to work with the RequestCultureProvider (essentially trying to find the UI Culture of the current request from within a user class) in ASP.NET Core 1.1
I have the following code in my Startup.cs under ConfigureServices:
services.AddSingleton<IRequestCultureProvider, RequestCultureProvider>();
The following error is being thrown at runtime:
Cannot instantiate implementation type 'Microsoft.AspNetCore.Localization.RequestCultureProvider' for service type 'Microsoft.AspNetCore.Localization.IRequestCultureProvider
How do I get around this? Or is there another method for getting the CurrentUICulture from within a user class.
Concrete examples appreciated.
Microsoft.AspNetCore.Localization.RequestCultureProvider
is an abstract class, so it cannot be instantiated like this.
I believe the intention of the framework is for you to use Features
not Services
:
var requestCultureFeature = context.Features.Get<IRequestCultureFeature>();
In conjunction with adding the RequestLocalizationMiddleware
that sets the feature.
RequestCultureProvider
is used for configuring RequestLocalizationOptions
that is used by RequestLocalizeationMiddleware (using DI for IOptions<RequestLocalizationOptions>
), so it isn't intended to be resolved as a service on its own
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With