Friday, March 8, 2019

Problem with IStringLocalizer injection

Hi,

I'm really new to .net core programming and I came across this issue which I can't wrap my head around. The solution builds fine and the homepage comes up, but when I do any action, like try to login I get this error: (AcademiejaarInst is a domain class)

InvalidOperationException: No suitable constructor found for entity type 'AcademiejaarInst'. The following constructors had parameters that could not be bound to properties of the entity type: cannot bind 'localizer' in 'AcademiejaarInst(IStringLocalizer<SharedResource> localizer)'. 

ctor of AcademiejaarInst

public class AcademiejaarInst { private static IStringLocalizer<SharedResource> _localizer; public AcademiejaarInst(IStringLocalizer<SharedResource> localizer) { _localizer = localizer; } ... 

This also is the case if I try to do the migrations. Obviously something's not right with the Localization Injection but I don't know why. These are the relevant LoCs in StartUp.cs

 public void ConfigureServices(IServiceCollection services) { ... services.AddMvc(config => ... ) .AddViewLocalization(o => o.ResourcesPath = "Resources") .AddDataAnnotationsLocalization(options => { options.DataAnnotationLocalizerProvider = (type, factory) => factory.Create(typeof(SharedResource)); }); // I tried this but was absolutely not sure this would work. services.AddTransient<AcademiejaarInst>(); services.AddSingleton<IStringLocalizer, StringLocalizer<SharedResource>>(); services.AddLocalization(o => o.ResourcesPath = "Resources"); services.Configure<RequestLocalizationOptions>(options => { var supportedCultures = new[] { new CultureInfo("nl-BE") }; options.DefaultRequestCulture = new RequestCulture("nl-BE", "nl_BE"); options.SupportedCultures = supportedCultures; options.SupportedUICultures = supportedCultures; }); ... } 

Many thanks for any help!

Problem with IStringLocalizer injection Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team