Factories depending on injected EF context fail if left to run in background #77
-
Hi, I noticed when trying out the FailSafe/FactorySoftTimeout feature that the idea of letting the factory complete in a background task does not work when using an EF context inside the factory. The context is created using DI and gets disposed when then request is complete which then causes the factory to fail which could lead to a situation where the cache is never repopulated. I understand why this is happening and its not a bug in FusionCache but i was curious if anyone has a clever solution to this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Hi @tjosgood and thanks for considering FusionCache! Yes you are correct: it's not a bug in EF nor in FusionCache, per se, but more like the crossing of 2 behaviours in 2 separate libs. It was already noticed in the past by another member of the community: you can read more aobut that here where there's also a suggested solution that worked well. In case you have additional suggestions or a different idea about how to make the EF+FusionCache integration better I would really like to know 😊 Also, the next item on my backlog happens to be expanding the docs a little bit, to include some sort of a cookbook with common usage examples, one of which is exactly an EF+FusionCache usage! When I'll publish it (hopefully very soon) would you be so kind to take a look at it and tell me what you think? Thanks. |
Beta Was this translation helpful? Give feedback.
-
Yea this sounds like a good solution, maybe I will try a little extension method for FusionCache that wraps GetOrSet and takes the usual params plus a context class and wraps the factory with a throwaway scope and passes that context to the factory Thanks for the help, great library! |
Beta Was this translation helpful? Give feedback.
Hi @tjosgood and thanks for considering FusionCache!
Yes you are correct: it's not a bug in EF nor in FusionCache, per se, but more like the crossing of 2 behaviours in 2 separate libs.
It was already noticed in the past by another member of the community: you can read more aobut that here where there's also a suggested solution that worked well.
In case you have additional suggestions or a different idea about how to make the EF+FusionCache integration better I would really like to know 😊
Also, the next item on my backlog happens to be expanding the docs a little bit, to include some sort of a cookbook with common usage examples, one of which is exactly an EF+FusionCache usage!
When I'll…