damienbod / AspNetCoreLocalization

Localization.SqlLocalizer & ASP.NET Core MVC Localization Examples
http://damienbod.com/2015/10/21/asp-net-5-mvc-6-localization/
MIT License
251 stars 101 forks source link

Fix EF Core context to dispose, remove singleton due to connection problems #62

Open damienbod opened 5 years ago

jakakonda commented 4 years ago

Hello!

I have a bit of an issue with this task. Namely getting concurrency exceptions.

I've been searching through the code a bit to see if I could help with the task, and from what I could find the blocking occurrences are the following services:

Due to the caching it makes sense to keep them as Singleton. I'd go with changing the DbContext scope to Scoped or Transient and consume it as it in intended in background service (consume IServiceProvider and create a scope, docs).

If (almost) all lock (_context) in the SqlLocalizerFactory are replaced with creating a scope, the issue should be resolved.

Please correct me if I'm wrong and if I missed any case since I'm not using the library to the full extent. If this is it, I could make the necessary changes.