Base solution for your next web application
Open Closed

EntityCache repository thread safety #7084


User avatar
0
antonis created

Hi,

EntityCache is a singleton class. I saw the code of abp and noticed that a IRepository is injected into EntityCache. Since entitycache is singleton and dependency is scoped these would lead to captive dependency and even worse the same repository instance will be used by whatever other service is registered as singleton and uses that repository. Eventually this would cause bigger problems since dbcontext is not thread safe.

Can you advise?

Thanks

Markdown is supported
Copy & paste or drag & drop images (max 30 MB per image)

3 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    EntityCache is not a singleton, right?

    https://aspnetboilerplate.com/Pages/Documents/Caching#entity-caching

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    0
    antonis created

    If it is a transient how it is caching then since every request has its own PersonCache?

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)
  • User Avatar
    1
    maliming created
    Support Team

    Because the ICacheManager used internally is a singleton.

    Markdown is supported
    Copy & paste or drag & drop images (max 30 MB per image)