LazZiya / XLocalizer

Localizer package for Asp.Net Core web applications, powered by online translation and auto resource creating.
https://docs.ziyad.info
129 stars 14 forks source link

Blazor AddXDbLocalizer #32

Closed franklupo closed 2 years ago

franklupo commented 2 years ago

HI, is it possible to use AddXDbLocalizer with Blazor?

bets regards

LazZiya commented 2 years ago

Hi,

I didn't try it, but I assume it should work.

Best regards,

franklupo commented 2 years ago

i have a problem with AddDbContext from scope to transient.

franklupo commented 2 years ago

Hi,

InvalidOperationException: Cannot consume scoped service 'Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage.ProtectedLocalStorage' from singleton 'XLocalizer.DB.IDbResourceProvider'.

How to resolve?

LazZiya commented 2 years ago

It seems your DB is registered as a scoped service, you have to register it as Transient.

services.AddDbContext<ApplicationDbContext>(options =>
        options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")), 
        ServiceLifetime.Transient, 
        ServiceLifetime.Transient);
franklupo commented 2 years ago

Not work

LazZiya commented 2 years ago

Well, just noticed this error is relevant to Microsoft.AspNetCore.Components.Server.ProtectedBrowserStorage.ProtectedLocalStorage, in this case this library wont help for the time being. I can't promise to develop a solution soon, but you may try to change the lifecycle of the mentioned service.

franklupo commented 2 years ago

Grazie