I am using ITicketStore as per this article. In this DbContext is created whenever required to perform any database operations.
In my code instead of creating the DbContext by using() syntax, injecting through the constructor. Everything was working fine until the code goes production. Started getting bellow exceptions when traffic increased.
- System.InvalidOperationException A second operation started on this context before a previous operation completed.
- Microsoft.EntityFrameworkCore.DbUpdateConcurrencyException
This probably because ITicketStore is a singleton and injecting DbContext using DI that shared the same DbContext instance between multiple threads.
I changed the code to create a DbContext instance by using() and it's working fine now.
But I am trying to find out any way to make DbContext work by injecting through DI.