You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am building a standard ASP.NET Core 3.1 application using Entity Framework core. In my EF model, I have configured a property with the [ConcurrencyCheck] attribute to protect my data from concurrent update.
With this in place, I now have a DbUpdateConcurrencyException that fires whenever there's a concurrent update. The strategy proposed by Microsoft is the following. Unfortunately, it just adds more code to be tested and it gets really messy with nested object.
Instead of adding more (buggy) code that is almost never executed, I would like to solve the problem differently. My thinking is to put a new middleware in my ASP.NET pipeline. This middleware would:
detect exceptions of type DbUpdateConcurrencyException.
when they occur, it would create a new IOC scope so that a new Entity Framework scope is created and we start with a brand new change tracker
it then retries executing the same operation with the new IOC scope
With this strategy, I would solve the problems for all kinds of concurrency conflicts without needing to add code for all my different entities.
But my problem is this:
how can I start a new IOC scope from within the ASP.NET Core pipeline?
where should I place my middleware in the pipeline?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am building a standard ASP.NET Core 3.1 application using Entity Framework core. In my EF model, I have configured a property with the
[ConcurrencyCheck]
attribute to protect my data from concurrent update.With this in place, I now have a
DbUpdateConcurrencyException
that fires whenever there's a concurrent update. The strategy proposed by Microsoft is the following. Unfortunately, it just adds more code to be tested and it gets really messy with nested object.Instead of adding more (buggy) code that is almost never executed, I would like to solve the problem differently. My thinking is to put a new middleware in my ASP.NET pipeline. This middleware would:
DbUpdateConcurrencyException
.With this strategy, I would solve the problems for all kinds of concurrency conflicts without needing to add code for all my different entities.
But my problem is this:
Beta Was this translation helpful? Give feedback.
All reactions